github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/middleware/requestCallback_test.go (about) 1 package main 2 3 import ( 4 "context" 5 "errors" 6 "net/http" 7 "strings" 8 "testing" 9 10 "github.com/gospider007/requests" 11 ) 12 13 func TestRequestCallBack(t *testing.T) { 14 _, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{ 15 RequestCallBack: func(ctx context.Context, request *http.Request, response *http.Response) error { 16 if response != nil { 17 if response.ContentLength > 100 { 18 return errors.New("max length") 19 } 20 } 21 return nil 22 }, 23 }) 24 if err == nil { 25 t.Error("err is nil") 26 } 27 if !strings.Contains(err.Error(), "max length") { 28 t.Error("err is not max length") 29 } 30 }