mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
32 lines
538 B
Go
32 lines
538 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/gospider007/requests"
|
|
)
|
|
|
|
func TestMaxRetries(t *testing.T) {
|
|
n := 0
|
|
resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
|
|
MaxRetries: 3,
|
|
ResultCallBack: func(ctx *requests.Response) error {
|
|
if n == 0 {
|
|
n++
|
|
return errors.New("try")
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if resp.StatusCode() != 200 {
|
|
t.Error("resp.StatusCode!= 200")
|
|
}
|
|
if n != 1 {
|
|
t.Error("n!=1")
|
|
}
|
|
}
|