github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/middleware/resultCallBack_test.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"testing"
     7  
     8  	"github.com/gospider007/requests"
     9  )
    10  
    11  func TestResultCallBack(t *testing.T) {
    12  	var code int
    13  	_, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{
    14  		ResultCallBack: func(ctx context.Context, option *requests.RequestOption, response *requests.Response) error {
    15  			if response.StatusCode() != 200 {
    16  				return errors.New("resp.StatusCode!= 200")
    17  			}
    18  			code = response.StatusCode()
    19  			return nil
    20  		},
    21  	})
    22  	if err != nil {
    23  		t.Error(err)
    24  	}
    25  	if code != 200 {
    26  		t.Error("code!= 200")
    27  	}
    28  }