mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
27 lines
556 B
Go
27 lines
556 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gospider007/requests"
|
|
)
|
|
|
|
func TestRequestCallBack(t *testing.T) {
|
|
_, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
|
|
RequestCallBack: func(ctx *requests.Response) error {
|
|
response := ctx.Response()
|
|
if response != nil {
|
|
if response.ContentLength > 100 {
|
|
return errors.New("max length")
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
if !strings.Contains(err.Error(), "max length") {
|
|
t.Error("err is not max length")
|
|
}
|
|
}
|