github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/middleware/optionltCallBack_test.go (about) 1 package main 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/gospider007/requests" 8 ) 9 10 func TestOptionCallBack(t *testing.T) { 11 resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{ 12 OptionCallBack: func(ctx context.Context, option *requests.RequestOption) error { 13 option.Params = map[string]string{"name": "test"} 14 return nil 15 }, 16 }) 17 if err != nil { 18 t.Error(err) 19 } 20 if resp.StatusCode() != 200 { 21 t.Error("resp.StatusCode!= 200") 22 } 23 jsonData, err := resp.Json() 24 if err != nil { 25 t.Error(err) 26 } 27 if jsonData.Get("args.name").String() != "test" { 28 t.Error("jsonData.Get(\"args.name\").String()!= test") 29 } 30 }