diff --git a/client/httplib/httplib_test.go b/client/httplib/httplib_test.go index f6be8571..88935715 100644 --- a/client/httplib/httplib_test.go +++ b/client/httplib/httplib_test.go @@ -15,6 +15,7 @@ package httplib import ( + "context" "errors" "io/ioutil" "net" @@ -23,6 +24,8 @@ import ( "strings" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestResponse(t *testing.T) { @@ -284,3 +287,16 @@ func TestHeader(t *testing.T) { } t.Log(str) } + +// TestAddFilter make sure that AddFilters only work for the specific request +func TestAddFilter(t *testing.T) { + req := Get("http://beego.me") + req.AddFilters(func(next Filter) Filter { + return func(ctx context.Context, req *BeegoHTTPRequest) (*http.Response, error) { + return next(ctx, req) + } + }) + + r := Get("http://beego.me") + assert.Equal(t, 1, len(req.setting.FilterChains)-len(r.setting.FilterChains)) +}