Add test for httplib

This commit is contained in:
Ming Deng 2020-10-27 21:54:43 +08:00
parent 9524036aab
commit d07a1eaa8e
1 changed files with 16 additions and 0 deletions

View File

@ -15,6 +15,7 @@
package httplib package httplib
import ( import (
"context"
"errors" "errors"
"io/ioutil" "io/ioutil"
"net" "net"
@ -23,6 +24,8 @@ import (
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
) )
func TestResponse(t *testing.T) { func TestResponse(t *testing.T) {
@ -284,3 +287,16 @@ func TestHeader(t *testing.T) {
} }
t.Log(str) 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))
}