From 76768373374a1b498df616841dcb8ca9b5f65049 Mon Sep 17 00:00:00 2001 From: eyasliu Date: Sun, 17 Jan 2021 18:05:29 +0800 Subject: [PATCH] fix abort test --- net/ghttp/ghttp_unit_client_test.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/net/ghttp/ghttp_unit_client_test.go b/net/ghttp/ghttp_unit_client_test.go index f951c858a..baf13d09b 100644 --- a/net/ghttp/ghttp_unit_client_test.go +++ b/net/ghttp/ghttp_unit_client_test.go @@ -10,14 +10,16 @@ import ( "bytes" "context" "fmt" - "github.com/gogf/gf/debug/gdebug" - "github.com/gogf/gf/os/gfile" - "github.com/gogf/gf/util/guid" "io/ioutil" "net/http" "testing" "time" + "github.com/gogf/gf/debug/gdebug" + "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/os/gfile" + "github.com/gogf/gf/util/guid" + "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/test/gtest" @@ -340,10 +342,8 @@ func Test_Client_Middleware(t *testing.T) { p, _ := ports.PopRand() s := g.Server(p) isServerHandler := false - //respStr := "test resp str" s.BindHandler("/", func(r *ghttp.Request) { isServerHandler = true - //r.Response.Write(respStr) }) s.SetPort(p) s.SetDumpRouterMap(false) @@ -381,6 +381,7 @@ func Test_Client_Middleware(t *testing.T) { // test abort, abort will not send str3 := "" + abortStr := "abort request" c = ghttp.NewClient().SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)).Use(func(c *ghttp.Client, r *http.Request) (resp *ghttp.ClientResponse, err error) { str3 += "a" resp, err = c.MiddlewareNext(r) @@ -388,11 +389,7 @@ func Test_Client_Middleware(t *testing.T) { return }).Use(func(c *ghttp.Client, r *http.Request) (*ghttp.ClientResponse, error) { str3 += "c" - resp, err := c.MiddlewareAbort(r) - str3 += "d" - resp, err = c.MiddlewareNext(r) - str3 += "e" - return resp, err + return nil, gerror.New(abortStr) }).Use(func(c *ghttp.Client, r *http.Request) (resp *ghttp.ClientResponse, err error) { str3 += "f" resp, err = c.MiddlewareNext(r) @@ -400,8 +397,8 @@ func Test_Client_Middleware(t *testing.T) { return }) resp, err = c.Get("/") - t.Assert(str3, "acdeb") - t.Assert(err.Error(), "http request abort") + t.Assert(str3, "acb") + t.Assert(err.Error(), abortStr) t.Assert(resp, nil) }) }