1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-24 13:10:55 +00:00

Merge pull request #4281 from flycash/httplibTest

Add test for httplib
This commit is contained in:
Ming Deng 2020-10-27 22:08:35 +08:00 committed by GitHub
commit 471ebba64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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))
}