Files
requests/test/middleware/requestCallback_test.go
赵小小 ee64501285 sync
2024-06-11 22:46:32 +08:00

31 lines
642 B
Go

package main
import (
"context"
"errors"
"net/http"
"strings"
"testing"
"github.com/gospider007/requests"
)
func TestRequestCallBack(t *testing.T) {
_, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
RequestCallBack: func(ctx context.Context, request *http.Request, response *http.Response) error {
if response != nil {
if response.ContentLength > 100 {
return errors.New("max length")
}
}
return nil
},
})
if err == nil {
t.Error("err is nil")
}
if !strings.Contains(err.Error(), "max length") {
t.Error("err is not max length")
}
}