mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 20:28:17 +08:00
add context for Client of package ghttp
This commit is contained in:
parent
dd4e08e88d
commit
131214151c
@ -37,7 +37,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
url := fmt.Sprintf("http://127.0.0.1:%d", p)
|
||||
client := g.Client().SetPrefix(url).ContentJson().SetDump(true)
|
||||
r, err := client.Post("/hello", g.Map{"field": "test_for_request_body"})
|
||||
r, err := client.Post(ctx, "/hello", g.Map{"field": "test_for_request_body"})
|
||||
t.Assert(err, nil)
|
||||
dumpedText := r.RawRequest()
|
||||
t.Assert(gstr.Contains(dumpedText, "test_for_request_body"), true)
|
||||
@ -46,7 +46,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
|
||||
t.Assert(gstr.Contains(dumpedText2, "test_for_response_body"), true)
|
||||
|
||||
client2 := g.Client().SetPrefix(url).ContentType("text/html")
|
||||
r2, err := client2.Dump().Post("/hello2", g.Map{"field": "test_for_request_body"})
|
||||
r2, err := client2.Dump().Post(ctx, "/hello2", g.Map{"field": "test_for_request_body"})
|
||||
t.Assert(err, nil)
|
||||
dumpedText3 := r2.RawRequest()
|
||||
t.Assert(gstr.Contains(dumpedText3, "test_for_request_body"), true)
|
||||
|
@ -42,10 +42,10 @@ func Test_Client_Basic(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(url)
|
||||
|
||||
t.Assert(g.Client().GetContent(""), ``)
|
||||
t.Assert(client.GetContent("/hello"), `hello`)
|
||||
t.Assert(g.Client().GetContent(ctx, ""), ``)
|
||||
t.Assert(client.GetContent(ctx, "/hello"), `hello`)
|
||||
|
||||
_, err := g.Client().Post("")
|
||||
_, err := g.Client().Post(ctx, "")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
}
|
||||
@ -69,8 +69,8 @@ func Test_Client_BasicAuth(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.BasicAuth("admin", "123").GetContent("/auth"), "0")
|
||||
t.Assert(c.BasicAuth("admin", "admin").GetContent("/auth"), "1")
|
||||
t.Assert(c.BasicAuth("admin", "123").GetContent(ctx, "/auth"), "0")
|
||||
t.Assert(c.BasicAuth("admin", "admin").GetContent(ctx, "/auth"), "1")
|
||||
})
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ func Test_Client_Cookie(t *testing.T) {
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
c.SetCookie("test", "0123456789")
|
||||
t.Assert(c.PostContent("/cookie"), "0123456789")
|
||||
t.Assert(c.PostContent(ctx, "/cookie"), "0123456789")
|
||||
})
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ func Test_Client_MapParam(t *testing.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(c.GetContent("/map", g.Map{"test": "1234567890"}), "1234567890")
|
||||
t.Assert(c.GetContent(ctx, "/map", g.Map{"test": "1234567890"}), "1234567890")
|
||||
})
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ func Test_Client_Cookies(t *testing.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
resp, err := c.Get("/cookie")
|
||||
resp, err := c.Get(ctx, "/cookie")
|
||||
t.Assert(err, nil)
|
||||
defer resp.Close()
|
||||
|
||||
@ -167,9 +167,9 @@ func Test_Client_Chain_Header(t *testing.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(c.Header(g.MapStrStr{"test1": "1234567890"}).GetContent("/header1"), "1234567890")
|
||||
t.Assert(c.HeaderRaw("test1: 1234567890\ntest2: abcdefg").GetContent("/header1"), "1234567890")
|
||||
t.Assert(c.HeaderRaw("test1: 1234567890\ntest2: abcdefg").GetContent("/header2"), "abcdefg")
|
||||
t.Assert(c.Header(g.MapStrStr{"test1": "1234567890"}).GetContent(ctx, "/header1"), "1234567890")
|
||||
t.Assert(c.HeaderRaw("test1: 1234567890\ntest2: abcdefg").GetContent(ctx, "/header1"), "1234567890")
|
||||
t.Assert(c.HeaderRaw("test1: 1234567890\ntest2: abcdefg").GetContent(ctx, "/header2"), "abcdefg")
|
||||
})
|
||||
}
|
||||
|
||||
@ -191,10 +191,10 @@ func Test_Client_Chain_Context(t *testing.T) {
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
t.Assert(c.Ctx(ctx).GetContent("/context"), "")
|
||||
t.Assert(c.GetContent(ctx, "/context"), "")
|
||||
|
||||
ctx, _ = context.WithTimeout(context.Background(), 2000*time.Millisecond)
|
||||
t.Assert(c.Ctx(ctx).GetContent("/context"), "ok")
|
||||
t.Assert(c.GetContent(ctx, "/context"), "ok")
|
||||
})
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ func Test_Client_Chain_Timeout(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.Timeout(100*time.Millisecond).GetContent("/timeout"), "")
|
||||
t.Assert(c.Timeout(2000*time.Millisecond).GetContent("/timeout"), "ok")
|
||||
t.Assert(c.Timeout(100*time.Millisecond).GetContent(ctx, "/timeout"), "")
|
||||
t.Assert(c.Timeout(2000*time.Millisecond).GetContent(ctx, "/timeout"), "ok")
|
||||
})
|
||||
}
|
||||
|
||||
@ -234,17 +234,17 @@ func Test_Client_Chain_ContentJson(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.ContentJson().PostContent("/json", g.Map{
|
||||
t.Assert(c.ContentJson().PostContent(ctx, "/json", g.Map{
|
||||
"name": "john",
|
||||
"score": 100,
|
||||
}), "john100")
|
||||
t.Assert(c.ContentJson().PostContent("/json", `{"name":"john", "score":100}`), "john100")
|
||||
t.Assert(c.ContentJson().PostContent(ctx, "/json", `{"name":"john", "score":100}`), "john100")
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
Score int `json:"score"`
|
||||
}
|
||||
t.Assert(c.ContentJson().PostContent("/json", User{"john", 100}), "john100")
|
||||
t.Assert(c.ContentJson().PostContent(ctx, "/json", User{"john", 100}), "john100")
|
||||
})
|
||||
}
|
||||
|
||||
@ -263,17 +263,17 @@ func Test_Client_Chain_ContentXml(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.ContentXml().PostContent("/xml", g.Map{
|
||||
t.Assert(c.ContentXml().PostContent(ctx, "/xml", g.Map{
|
||||
"name": "john",
|
||||
"score": 100,
|
||||
}), "john100")
|
||||
t.Assert(c.ContentXml().PostContent("/xml", `{"name":"john", "score":100}`), "john100")
|
||||
t.Assert(c.ContentXml().PostContent(ctx, "/xml", `{"name":"john", "score":100}`), "john100")
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
Score int `json:"score"`
|
||||
}
|
||||
t.Assert(c.ContentXml().PostContent("/xml", User{"john", 100}), "john100")
|
||||
t.Assert(c.ContentXml().PostContent(ctx, "/xml", User{"john", 100}), "john100")
|
||||
})
|
||||
}
|
||||
|
||||
@ -292,8 +292,8 @@ func Test_Client_Param_Containing_Special_Char(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.PostContent("/", "k1=MTIxMg==&k2=100"), "k1=MTIxMg==&k2=100")
|
||||
t.Assert(c.PostContent("/", g.Map{
|
||||
t.Assert(c.PostContent(ctx, "/", "k1=MTIxMg==&k2=100"), "k1=MTIxMg==&k2=100")
|
||||
t.Assert(c.PostContent(ctx, "/", g.Map{
|
||||
"k1": "MTIxMg==",
|
||||
"k2": 100,
|
||||
}), "k1=MTIxMg==&k2=100")
|
||||
@ -334,7 +334,7 @@ func Test_Client_File_And_Param(t *testing.T) {
|
||||
}
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.PostContent("/", data), data["json"].(string)+gfile.GetContents(path))
|
||||
t.Assert(c.PostContent(ctx, "/", data), data["json"].(string)+gfile.GetContents(path))
|
||||
})
|
||||
}
|
||||
|
||||
@ -386,7 +386,7 @@ func Test_Client_Middleware(t *testing.T) {
|
||||
str1 += "f"
|
||||
return
|
||||
})
|
||||
resp, err := c.Get("/")
|
||||
resp, err := c.Get(ctx, "/")
|
||||
t.Assert(str1, "acefdb")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp.ReadAllString(), str2)
|
||||
@ -415,7 +415,7 @@ func Test_Client_Middleware(t *testing.T) {
|
||||
str3 += "g"
|
||||
return
|
||||
})
|
||||
resp, err = c.Get("/")
|
||||
resp, err = c.Get(ctx, "/")
|
||||
t.Assert(err, abortStr)
|
||||
t.Assert(str3, "acb")
|
||||
t.Assert(resp, nil)
|
||||
@ -438,6 +438,6 @@ func Test_Client_Agent(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client().SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
c.SetAgent("test")
|
||||
t.Assert(c.GetContent("/"), "test")
|
||||
t.Assert(c.GetContent(ctx, "/"), "test")
|
||||
})
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ func Test_ClientMaxBodySize(t *testing.T) {
|
||||
data[i] = 'a'
|
||||
}
|
||||
t.Assert(
|
||||
gstr.Trim(c.PostContent("/", data)),
|
||||
gstr.Trim(c.PostContent(ctx, "/", data)),
|
||||
data[:1024],
|
||||
)
|
||||
})
|
||||
@ -133,7 +133,7 @@ func Test_ClientMaxBodySize_File(t *testing.T) {
|
||||
t.Assert(gfile.PutBytes(path, data), nil)
|
||||
defer gfile.Remove(path)
|
||||
t.Assert(
|
||||
gstr.Trim(c.PostContent("/", "name=john&file=@file:"+path)),
|
||||
gstr.Trim(c.PostContent(ctx, "/", "name=john&file=@file:"+path)),
|
||||
"ok",
|
||||
)
|
||||
})
|
||||
@ -151,7 +151,7 @@ func Test_ClientMaxBodySize_File(t *testing.T) {
|
||||
t.Assert(gfile.PutBytes(path, data), nil)
|
||||
defer gfile.Remove(path)
|
||||
t.Assert(
|
||||
gstr.Trim(c.PostContent("/", "name=john&file=@file:"+path)),
|
||||
gstr.Trim(c.PostContent(ctx, "/", "name=john&file=@file:"+path)),
|
||||
"Invalid Request: http: request body too large",
|
||||
)
|
||||
})
|
||||
|
@ -38,6 +38,6 @@ func Test_Context(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), `123`)
|
||||
t.Assert(client.GetContent(ctx, "/"), `123`)
|
||||
})
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func Test_Cookie(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
r1, e1 := client.Get("/set?k=key1&v=100")
|
||||
r1, e1 := client.Get(ctx, "/set?k=key1&v=100")
|
||||
if r1 != nil {
|
||||
defer r1.Close()
|
||||
}
|
||||
@ -47,16 +47,16 @@ func Test_Cookie(t *testing.T) {
|
||||
t.Assert(e1, nil)
|
||||
t.Assert(r1.ReadAllString(), "")
|
||||
|
||||
t.Assert(client.GetContent("/set?k=key2&v=200"), "")
|
||||
t.Assert(client.GetContent(ctx, "/set?k=key2&v=200"), "")
|
||||
|
||||
t.Assert(client.GetContent("/get?k=key1"), "100")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent("/get?k=key3"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key1"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key3"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key4"), "")
|
||||
t.Assert(client.GetContent("/get?k=key1"), "")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key3"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key3"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key4"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
})
|
||||
}
|
||||
|
||||
@ -85,22 +85,22 @@ func Test_SetHttpCookie(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
r1, e1 := client.Get("/set?k=key1&v=100")
|
||||
r1, e1 := client.Get(ctx, "/set?k=key1&v=100")
|
||||
if r1 != nil {
|
||||
defer r1.Close()
|
||||
}
|
||||
t.Assert(e1, nil)
|
||||
t.Assert(r1.ReadAllString(), "")
|
||||
|
||||
t.Assert(client.GetContent("/set?k=key2&v=200"), "")
|
||||
t.Assert(client.GetContent(ctx, "/set?k=key2&v=200"), "")
|
||||
|
||||
t.Assert(client.GetContent("/get?k=key1"), "100")
|
||||
//t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
//t.Assert(client.GetContent("/get?k=key3"), "")
|
||||
//t.Assert(client.GetContent("/remove?k=key1"), "")
|
||||
//t.Assert(client.GetContent("/remove?k=key3"), "")
|
||||
//t.Assert(client.GetContent("/remove?k=key4"), "")
|
||||
//t.Assert(client.GetContent("/get?k=key1"), "")
|
||||
//t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "100")
|
||||
//t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
//t.Assert(client.GetContent(ctx, "/get?k=key3"), "")
|
||||
//t.Assert(client.GetContent(ctx, "/remove?k=key1"), "")
|
||||
//t.Assert(client.GetContent(ctx, "/remove?k=key3"), "")
|
||||
//t.Assert(client.GetContent(ctx, "/remove?k=key4"), "")
|
||||
//t.Assert(client.GetContent(ctx, "/get?k=key1"), "")
|
||||
//t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
})
|
||||
}
|
||||
|
@ -41,6 +41,6 @@ func Test_Error_Code(t *testing.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(c.GetContent("/"), "10000")
|
||||
t.Assert(c.GetContent(ctx, "/"), "10000")
|
||||
})
|
||||
}
|
||||
|
@ -45,15 +45,15 @@ func Test_HTTPS_Basic(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.AssertIN(gstr.Trim(c.GetContent("/")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
t.AssertIN(gstr.Trim(c.GetContent("/test")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/test")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
})
|
||||
// HTTPS
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", p))
|
||||
t.Assert(c.GetContent("/"), "Not Found")
|
||||
t.Assert(c.GetContent("/test"), "test")
|
||||
t.Assert(c.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(c.GetContent(ctx, "/test"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -80,15 +80,15 @@ func Test_HTTPS_Resource(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.AssertIN(gstr.Trim(c.GetContent("/")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
t.AssertIN(gstr.Trim(c.GetContent("/test")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/test")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
|
||||
})
|
||||
// HTTPS
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", p))
|
||||
t.Assert(c.GetContent("/"), "Not Found")
|
||||
t.Assert(c.GetContent("/test"), "test")
|
||||
t.Assert(c.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(c.GetContent(ctx, "/test"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -119,14 +119,14 @@ func Test_HTTPS_HTTP_Basic(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", portHttp))
|
||||
t.Assert(c.GetContent("/"), "Not Found")
|
||||
t.Assert(c.GetContent("/test"), "test")
|
||||
t.Assert(c.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(c.GetContent(ctx, "/test"), "test")
|
||||
})
|
||||
// HTTPS
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", portHttps))
|
||||
t.Assert(c.GetContent("/"), "Not Found")
|
||||
t.Assert(c.GetContent("/test"), "test")
|
||||
t.Assert(c.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(c.GetContent(ctx, "/test"), "test")
|
||||
})
|
||||
}
|
||||
|
@ -7,11 +7,13 @@
|
||||
package ghttp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/container/garray"
|
||||
"github.com/gogf/gf/os/genv"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx = context.TODO()
|
||||
ports = garray.NewIntArray(true)
|
||||
)
|
||||
|
||||
|
@ -35,7 +35,7 @@ func TestRequest_GetRemoteIp(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "127.0.0.1")
|
||||
t.Assert(client.GetContent(ctx, "/"), "127.0.0.1")
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ func Test_Log(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/hello"), "hello")
|
||||
t.Assert(client.GetContent("/error"), "custom error")
|
||||
t.Assert(client.GetContent(ctx, "/hello"), "hello")
|
||||
t.Assert(client.GetContent(ctx, "/error"), "custom error")
|
||||
|
||||
logPath1 := gfile.Join(logDir, gtime.Now().Format("Y-m-d")+".log")
|
||||
t.Assert(gstr.Contains(gfile.GetContents(logPath1), "http server started listening on"), true)
|
||||
|
@ -34,6 +34,6 @@ func Test_GetUrl(t *testing.T) {
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.GetContent("/url"), prefix+"/url")
|
||||
t.Assert(client.GetContent(ctx, "/url"), prefix+"/url")
|
||||
})
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ func Test_BindMiddleware_Basic1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/test"), "1342")
|
||||
t.Assert(client.GetContent("/test/test"), "57test86")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "1342")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "57test86")
|
||||
})
|
||||
}
|
||||
|
||||
@ -80,9 +80,9 @@ func Test_BindMiddleware_Basic2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "12")
|
||||
t.Assert(client.GetContent("/test"), "12")
|
||||
t.Assert(client.GetContent("/test/test"), "1test2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "12")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "12")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "1test2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -120,13 +120,13 @@ func Test_BindMiddleware_Basic3(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/test"), "Not Found")
|
||||
t.Assert(client.PutContent("/test"), "1342")
|
||||
t.Assert(client.PostContent("/test"), "Not Found")
|
||||
t.Assert(client.GetContent("/test/test"), "test")
|
||||
t.Assert(client.PutContent("/test/test"), "test")
|
||||
t.Assert(client.PostContent("/test/test"), "57test86")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "Not Found")
|
||||
t.Assert(client.PutContent(ctx, "/test"), "1342")
|
||||
t.Assert(client.PostContent(ctx, "/test"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "test")
|
||||
t.Assert(client.PutContent(ctx, "/test/test"), "test")
|
||||
t.Assert(client.PostContent(ctx, "/test/test"), "57test86")
|
||||
})
|
||||
}
|
||||
|
||||
@ -156,9 +156,9 @@ func Test_BindMiddleware_Basic4(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/test"), "1test2")
|
||||
t.Assert(client.PutContent("/test/none"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "1test2")
|
||||
t.Assert(client.PutContent(ctx, "/test/none"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -185,10 +185,10 @@ func Test_Middleware_With_Static(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "index")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent("/none"), "Not Found")
|
||||
t.Assert(client.GetContent("/user/list"), "1list2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/none"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/user/list"), "1list2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -213,10 +213,10 @@ func Test_Middleware_Status(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/user/list"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/user/list"), "200")
|
||||
|
||||
resp, err := client.Get("/")
|
||||
resp, err := client.Get(ctx, "/")
|
||||
defer resp.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
@ -259,19 +259,19 @@ func Test_Middleware_Hook_With_Static(t *testing.T) {
|
||||
|
||||
// The length assert sometimes fails, so I added time.Sleep here for debug purpose.
|
||||
|
||||
t.Assert(client.GetContent("/"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/"), "index")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Assert(a.Len(), 2)
|
||||
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Assert(a.Len(), 4)
|
||||
|
||||
t.Assert(client.GetContent("/none"), "ab")
|
||||
t.Assert(client.GetContent(ctx, "/none"), "ab")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Assert(a.Len(), 6)
|
||||
|
||||
t.Assert(client.GetContent("/user/list"), "a1list2b")
|
||||
t.Assert(client.GetContent(ctx, "/user/list"), "a1list2b")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Assert(a.Len(), 8)
|
||||
})
|
||||
@ -296,10 +296,10 @@ func Test_BindMiddleware_Status(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/test"), "Not Found")
|
||||
t.Assert(client.GetContent("/test/test"), "test")
|
||||
t.Assert(client.GetContent("/test/test/test"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/test/test/test"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -329,8 +329,8 @@ func Test_BindMiddlewareDefault_Basic1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1342")
|
||||
t.Assert(client.GetContent("/test/test"), "13test42")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1342")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "13test42")
|
||||
})
|
||||
}
|
||||
|
||||
@ -360,10 +360,10 @@ func Test_BindMiddlewareDefault_Basic2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1342")
|
||||
t.Assert(client.PutContent("/"), "1342")
|
||||
t.Assert(client.GetContent("/test/test"), "1342")
|
||||
t.Assert(client.PutContent("/test/test"), "13test42")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1342")
|
||||
t.Assert(client.PutContent(ctx, "/"), "1342")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "1342")
|
||||
t.Assert(client.PutContent(ctx, "/test/test"), "13test42")
|
||||
})
|
||||
}
|
||||
|
||||
@ -391,8 +391,8 @@ func Test_BindMiddlewareDefault_Basic3(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "12")
|
||||
t.Assert(client.GetContent("/test/test"), "1test2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "12")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "1test2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -420,8 +420,8 @@ func Test_BindMiddlewareDefault_Basic4(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "21")
|
||||
t.Assert(client.GetContent("/test/test"), "2test1")
|
||||
t.Assert(client.GetContent(ctx, "/"), "21")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "2test1")
|
||||
})
|
||||
}
|
||||
|
||||
@ -449,8 +449,8 @@ func Test_BindMiddlewareDefault_Basic5(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "12")
|
||||
t.Assert(client.GetContent("/test/test"), "12test")
|
||||
t.Assert(client.GetContent(ctx, "/"), "12")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "12test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -473,8 +473,8 @@ func Test_BindMiddlewareDefault_Status(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/test/test"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -524,12 +524,12 @@ func Test_BindMiddlewareDefault_Basic6(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "13100Object Index20042")
|
||||
t.Assert(client.GetContent("/init"), "1342")
|
||||
t.Assert(client.GetContent("/shut"), "1342")
|
||||
t.Assert(client.GetContent("/index"), "13100Object Index20042")
|
||||
t.Assert(client.GetContent("/show"), "13100Object Show20042")
|
||||
t.Assert(client.GetContent("/none-exist"), "1342")
|
||||
t.Assert(client.GetContent(ctx, "/"), "13100Object Index20042")
|
||||
t.Assert(client.GetContent(ctx, "/init"), "1342")
|
||||
t.Assert(client.GetContent(ctx, "/shut"), "1342")
|
||||
t.Assert(client.GetContent(ctx, "/index"), "13100Object Index20042")
|
||||
t.Assert(client.GetContent(ctx, "/show"), "13100Object Show20042")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "1342")
|
||||
})
|
||||
}
|
||||
|
||||
@ -571,8 +571,8 @@ func Test_Hook_Middleware_Basic1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "ac1342bd")
|
||||
t.Assert(client.GetContent("/test/test"), "ac13test42bd")
|
||||
t.Assert(client.GetContent(ctx, "/"), "ac1342bd")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "ac13test42bd")
|
||||
})
|
||||
}
|
||||
|
||||
@ -609,13 +609,13 @@ func Test_Middleware_CORSAndAuth(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
// Common Checks.
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/api.v2"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
|
||||
// Auth Checks.
|
||||
t.Assert(client.PostContent("/api.v2/user/list"), "Forbidden")
|
||||
t.Assert(client.PostContent("/api.v2/user/list", "token=123456"), "list")
|
||||
t.Assert(client.PostContent(ctx, "/api.v2/user/list"), "Forbidden")
|
||||
t.Assert(client.PostContent(ctx, "/api.v2/user/list", "token=123456"), "list")
|
||||
// CORS Checks.
|
||||
resp, err := client.Post("/api.v2/user/list", "token=123456")
|
||||
resp, err := client.Post(ctx, "/api.v2/user/list", "token=123456")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
|
||||
t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With")
|
||||
@ -674,10 +674,10 @@ func Test_Middleware_Scope(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/scope1"), "a1b")
|
||||
t.Assert(client.GetContent("/scope2"), "ac2db")
|
||||
t.Assert(client.GetContent("/scope3"), "ae3fb")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/scope1"), "a1b")
|
||||
t.Assert(client.GetContent(ctx, "/scope2"), "ac2db")
|
||||
t.Assert(client.GetContent(ctx, "/scope3"), "ae3fb")
|
||||
})
|
||||
}
|
||||
|
||||
@ -709,6 +709,6 @@ func Test_Middleware_Panic(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "error")
|
||||
t.Assert(client.GetContent(ctx, "/"), "error")
|
||||
})
|
||||
}
|
||||
|
@ -33,18 +33,18 @@ func Test_Middleware_CORS1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
// Common Checks.
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/api.v2"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
|
||||
|
||||
// GET request does not any route.
|
||||
resp, err := client.Get("/api.v2/user/list")
|
||||
resp, err := client.Get(ctx, "/api.v2/user/list")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
resp.Close()
|
||||
|
||||
// POST request matches the route and CORS middleware.
|
||||
resp, err = client.Post("/api.v2/user/list")
|
||||
resp, err = client.Post(ctx, "/api.v2/user/list")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
|
||||
t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With")
|
||||
@ -58,7 +58,7 @@ func Test_Middleware_CORS1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader("Access-Control-Request-Method", "GET")
|
||||
resp, err := client.Options("/api.v2/user/list")
|
||||
resp, err := client.Options(ctx, "/api.v2/user/list")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
|
||||
t.Assert(resp.ReadAllString(), "Not Found")
|
||||
@ -70,7 +70,7 @@ func Test_Middleware_CORS1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader("Access-Control-Request-Method", "POST")
|
||||
resp, err := client.Options("/api.v2/user/list")
|
||||
resp, err := client.Options(ctx, "/api.v2/user/list")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
|
||||
t.Assert(resp.StatusCode, 200)
|
||||
@ -96,10 +96,10 @@ func Test_Middleware_CORS2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
// Common Checks.
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/api.v2"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
|
||||
// Get request.
|
||||
resp, err := client.Get("/api.v2/user/list/1")
|
||||
resp, err := client.Get(ctx, "/api.v2/user/list/1")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
|
||||
t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With")
|
||||
@ -114,7 +114,7 @@ func Test_Middleware_CORS2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader("Access-Control-Request-Method", "GET")
|
||||
resp, err := client.Options("/api.v2/user")
|
||||
resp, err := client.Options(ctx, "/api.v2/user")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
@ -125,7 +125,7 @@ func Test_Middleware_CORS2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader("Access-Control-Request-Method", "GET")
|
||||
resp, err := client.Options("/api.v2/user/list/1")
|
||||
resp, err := client.Options(ctx, "/api.v2/user/list/1")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
|
||||
t.Assert(resp.StatusCode, 200)
|
||||
@ -136,7 +136,7 @@ func Test_Middleware_CORS2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader("Access-Control-Request-Method", "POST")
|
||||
resp, err := client.Options("/api.v2/user/list/1")
|
||||
resp, err := client.Options(ctx, "/api.v2/user/list/1")
|
||||
t.Assert(err, nil)
|
||||
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
|
@ -30,27 +30,27 @@ func TestServer_EnablePProf(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
r, err := client.Get("/pprof/index")
|
||||
r, err := client.Get(ctx, "/pprof/index")
|
||||
Assert(err, nil)
|
||||
Assert(r.StatusCode, 200)
|
||||
r.Close()
|
||||
|
||||
r, err = client.Get("/pprof/cmdline")
|
||||
r, err = client.Get(ctx, "/pprof/cmdline")
|
||||
Assert(err, nil)
|
||||
Assert(r.StatusCode, 200)
|
||||
r.Close()
|
||||
|
||||
//r, err = client.Get("/pprof/profile")
|
||||
//r, err = client.Get(ctx, "/pprof/profile")
|
||||
//Assert(err, nil)
|
||||
//Assert(r.StatusCode, 200)
|
||||
//r.Close()
|
||||
|
||||
r, err = client.Get("/pprof/symbol")
|
||||
r, err = client.Get(ctx, "/pprof/symbol")
|
||||
Assert(err, nil)
|
||||
Assert(r.StatusCode, 200)
|
||||
r.Close()
|
||||
|
||||
r, err = client.Get("/pprof/trace")
|
||||
r, err = client.Get(ctx, "/pprof/trace")
|
||||
Assert(err, nil)
|
||||
Assert(r.StatusCode, 200)
|
||||
r.Close()
|
||||
|
@ -39,6 +39,6 @@ func Test_Request_SetCtx(t *testing.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(c.GetContent("/"), "1")
|
||||
t.Assert(c.GetContent(ctx, "/"), "1")
|
||||
})
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func Test_Params_File_Single(t *testing.T) {
|
||||
|
||||
srcPath := gdebug.TestDataPath("upload", "file1.txt")
|
||||
dstPath := gfile.Join(dstDirPath, "file1.txt")
|
||||
content := client.PostContent("/upload/single", g.Map{
|
||||
content := client.PostContent(ctx, "/upload/single", g.Map{
|
||||
"file": "@file:" + srcPath,
|
||||
})
|
||||
t.AssertNE(content, "")
|
||||
@ -62,7 +62,7 @@ func Test_Params_File_Single(t *testing.T) {
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
srcPath := gdebug.TestDataPath("upload", "file2.txt")
|
||||
content := client.PostContent("/upload/single", g.Map{
|
||||
content := client.PostContent(ctx, "/upload/single", g.Map{
|
||||
"file": "@file:" + srcPath,
|
||||
"randomlyRename": true,
|
||||
})
|
||||
@ -100,7 +100,7 @@ func Test_Params_File_CustomName(t *testing.T) {
|
||||
|
||||
srcPath := gdebug.TestDataPath("upload", "file1.txt")
|
||||
dstPath := gfile.Join(dstDirPath, "my.txt")
|
||||
content := client.PostContent("/upload/single", g.Map{
|
||||
content := client.PostContent(ctx, "/upload/single", g.Map{
|
||||
"file": "@file:" + srcPath,
|
||||
})
|
||||
t.AssertNE(content, "")
|
||||
@ -139,7 +139,7 @@ func Test_Params_File_Batch(t *testing.T) {
|
||||
srcPath2 := gdebug.TestDataPath("upload", "file2.txt")
|
||||
dstPath1 := gfile.Join(dstDirPath, "file1.txt")
|
||||
dstPath2 := gfile.Join(dstDirPath, "file2.txt")
|
||||
content := client.PostContent("/upload/batch", g.Map{
|
||||
content := client.PostContent(ctx, "/upload/batch", g.Map{
|
||||
"file[0]": "@file:" + srcPath1,
|
||||
"file[1]": "@file:" + srcPath2,
|
||||
})
|
||||
@ -157,7 +157,7 @@ func Test_Params_File_Batch(t *testing.T) {
|
||||
|
||||
srcPath1 := gdebug.TestDataPath("upload", "file1.txt")
|
||||
srcPath2 := gdebug.TestDataPath("upload", "file2.txt")
|
||||
content := client.PostContent("/upload/batch", g.Map{
|
||||
content := client.PostContent(ctx, "/upload/batch", g.Map{
|
||||
"file[0]": "@file:" + srcPath1,
|
||||
"file[1]": "@file:" + srcPath2,
|
||||
"randomlyRename": true,
|
||||
|
@ -54,10 +54,10 @@ func Test_Params_Json_Request(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/get", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
|
||||
t.Assert(client.GetContent("/map", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
|
||||
t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123"}`), `密码强度不足; 两次密码不一致`)
|
||||
t.Assert(client.GetContent(ctx, "/get", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
|
||||
t.Assert(client.GetContent(ctx, "/map", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123"}`), `密码强度不足; 两次密码不一致`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ func Test_Params_Json_Response(t *testing.T) {
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
map1 := make(map[string]interface{})
|
||||
err1 := json.UnmarshalUseNumber([]byte(client.GetContent("/json1")), &map1)
|
||||
err1 := json.UnmarshalUseNumber([]byte(client.GetContent(ctx, "/json1")), &map1)
|
||||
t.Assert(err1, nil)
|
||||
t.Assert(len(map1), 4)
|
||||
t.Assert(map1["Name"], "john")
|
||||
@ -153,7 +153,7 @@ func Test_Params_Json_Response(t *testing.T) {
|
||||
t.Assert(map1["password2"], "456")
|
||||
|
||||
map2 := make(map[string]interface{})
|
||||
err2 := json.UnmarshalUseNumber([]byte(client.GetContent("/json2")), &map2)
|
||||
err2 := json.UnmarshalUseNumber([]byte(client.GetContent(ctx, "/json2")), &map2)
|
||||
t.Assert(err2, nil)
|
||||
t.Assert(len(map2), 4)
|
||||
t.Assert(map2["Name"], "john")
|
||||
@ -162,14 +162,14 @@ func Test_Params_Json_Response(t *testing.T) {
|
||||
t.Assert(map2["password2"], "456")
|
||||
|
||||
map3 := make(map[string]interface{})
|
||||
err3 := json.UnmarshalUseNumber([]byte(client.GetContent("/json3")), &map3)
|
||||
err3 := json.UnmarshalUseNumber([]byte(client.GetContent(ctx, "/json3")), &map3)
|
||||
t.Assert(err3, nil)
|
||||
t.Assert(len(map3), 2)
|
||||
t.Assert(map3["success"], "true")
|
||||
t.Assert(map3["message"], g.Map{"body": "测试", "code": 3, "error": "error"})
|
||||
|
||||
map4 := make(map[string]interface{})
|
||||
err4 := json.UnmarshalUseNumber([]byte(client.GetContent("/json4")), &map4)
|
||||
err4 := json.UnmarshalUseNumber([]byte(client.GetContent(ctx, "/json4")), &map4)
|
||||
t.Assert(err4, nil)
|
||||
t.Assert(len(map4), 2)
|
||||
t.Assert(map4["success"], "true")
|
||||
|
@ -39,10 +39,10 @@ func Test_Params_Page(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/list"), `<span class="GPageSpan">首页</span><span class="GPageSpan">上一页</span><span class="GPageSpan">1</span><a class="GPageLink" href="/list?page=2" title="2">2</a><a class="GPageLink" href="/list?page=3" title="3">3</a><a class="GPageLink" href="/list?page=2" title="">下一页</a><a class="GPageLink" href="/list?page=3" title="">尾页</a>`)
|
||||
t.Assert(client.GetContent("/list?page=3"), `<a class="GPageLink" href="/list?page=1" title="">首页</a><a class="GPageLink" href="/list?page=2" title="">上一页</a><a class="GPageLink" href="/list?page=1" title="1">1</a><a class="GPageLink" href="/list?page=2" title="2">2</a><span class="GPageSpan">3</span><span class="GPageSpan">下一页</span><span class="GPageSpan">尾页</span>`)
|
||||
t.Assert(client.GetContent(ctx, "/list"), `<span class="GPageSpan">首页</span><span class="GPageSpan">上一页</span><span class="GPageSpan">1</span><a class="GPageLink" href="/list?page=2" title="2">2</a><a class="GPageLink" href="/list?page=3" title="3">3</a><a class="GPageLink" href="/list?page=2" title="">下一页</a><a class="GPageLink" href="/list?page=3" title="">尾页</a>`)
|
||||
t.Assert(client.GetContent(ctx, "/list?page=3"), `<a class="GPageLink" href="/list?page=1" title="">首页</a><a class="GPageLink" href="/list?page=2" title="">上一页</a><a class="GPageLink" href="/list?page=1" title="1">1</a><a class="GPageLink" href="/list?page=2" title="2">2</a><span class="GPageSpan">3</span><span class="GPageSpan">下一页</span><span class="GPageSpan">尾页</span>`)
|
||||
|
||||
t.Assert(client.GetContent("/list/1.html"), `<span class="GPageSpan">首页</span><span class="GPageSpan">上一页</span><span class="GPageSpan">1</span><a class="GPageLink" href="/list/2.html" title="2">2</a><a class="GPageLink" href="/list/3.html" title="3">3</a><a class="GPageLink" href="/list/2.html" title="">下一页</a><a class="GPageLink" href="/list/3.html" title="">尾页</a>`)
|
||||
t.Assert(client.GetContent("/list/3.html"), `<a class="GPageLink" href="/list/1.html" title="">首页</a><a class="GPageLink" href="/list/2.html" title="">上一页</a><a class="GPageLink" href="/list/1.html" title="1">1</a><a class="GPageLink" href="/list/2.html" title="2">2</a><span class="GPageSpan">3</span><span class="GPageSpan">下一页</span><span class="GPageSpan">尾页</span>`)
|
||||
t.Assert(client.GetContent(ctx, "/list/1.html"), `<span class="GPageSpan">首页</span><span class="GPageSpan">上一页</span><span class="GPageSpan">1</span><a class="GPageLink" href="/list/2.html" title="2">2</a><a class="GPageLink" href="/list/3.html" title="3">3</a><a class="GPageLink" href="/list/2.html" title="">下一页</a><a class="GPageLink" href="/list/3.html" title="">尾页</a>`)
|
||||
t.Assert(client.GetContent(ctx, "/list/3.html"), `<a class="GPageLink" href="/list/1.html" title="">首页</a><a class="GPageLink" href="/list/2.html" title="">上一页</a><a class="GPageLink" href="/list/1.html" title="1">1</a><a class="GPageLink" href="/list/2.html" title="2">2</a><span class="GPageSpan">3</span><span class="GPageSpan">下一页</span><span class="GPageSpan">尾页</span>`)
|
||||
})
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func Test_Params_Parse(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","map":{"id":1,"score":100}}`), `1100`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","map":{"id":1,"score":100}}`), `1100`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -69,10 +69,10 @@ func Test_Params_ParseQuery(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.GetContent("/parse-query"), `0`)
|
||||
t.Assert(c.GetContent("/parse-query?id=1&name=john"), `1john`)
|
||||
t.Assert(c.PostContent("/parse-query"), `0`)
|
||||
t.Assert(c.PostContent("/parse-query", g.Map{
|
||||
t.Assert(c.GetContent(ctx, "/parse-query"), `0`)
|
||||
t.Assert(c.GetContent(ctx, "/parse-query?id=1&name=john"), `1john`)
|
||||
t.Assert(c.PostContent(ctx, "/parse-query"), `0`)
|
||||
t.Assert(c.PostContent(ctx, "/parse-query", g.Map{
|
||||
"id": 1,
|
||||
"name": "john",
|
||||
}), `0`)
|
||||
@ -102,13 +102,13 @@ func Test_Params_ParseForm(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.GetContent("/parse-form"), `0`)
|
||||
t.Assert(c.GetContent("/parse-form", g.Map{
|
||||
t.Assert(c.GetContent(ctx, "/parse-form"), `0`)
|
||||
t.Assert(c.GetContent(ctx, "/parse-form", g.Map{
|
||||
"id": 1,
|
||||
"name": "john",
|
||||
}), 0)
|
||||
t.Assert(c.PostContent("/parse-form"), `0`)
|
||||
t.Assert(c.PostContent("/parse-form", g.Map{
|
||||
t.Assert(c.PostContent(ctx, "/parse-form"), `0`)
|
||||
t.Assert(c.PostContent(ctx, "/parse-form", g.Map{
|
||||
"id": 1,
|
||||
"name": "john",
|
||||
}), `1john`)
|
||||
@ -286,7 +286,7 @@ func Test_Params_ComplexJsonStruct(t *testing.T) {
|
||||
"version_tag": "test"
|
||||
}
|
||||
`
|
||||
t.Assert(client.PostContent("/parse", content), `{"AppId":5,"Name":"test","Type":"test","Cluster":"test","Replicas":1,"ContainerName":"test","ContainerImage":"nginx","VersionTag":"test","Namespace":"test","Id":0,"Status":0,"Metrics":"","InitImage":"","CpuRequest":10,"CpuLimit":100,"MemRequest":100,"MemLimit":1000,"MeshEnabled":0,"ContainerPorts":[{"Port":80,"Type":"tcp","Alias":"别名","Brief":"描述"}],"Labels":[{"Key":"app","Value":"test"}],"NodeSelector":[{"Key":"group","Value":"app"}],"EnvReserve":[{"Key":"NODE_IP","Value":"status.hostIP"}],"EnvGlobal":[{"Type":"string","Key":"NUMBER","Value":"1","Brief":"数据数量"}],"EnvContainer":[{"Type":"string","Key":"NAME","Value":"john","Brief":"用户环境变量"}],"Mounts":[],"LivenessProbe":{"Type":"tcpSocket","Port":80,"Path":"","Brief":"存活探针","Period":5,"InitialDelay":10,"TimeoutSeconds":0},"ReadinessProbe":{"Type":"tcpSocket","Port":80,"Path":"","Brief":"就绪探针","Period":5,"InitialDelay":10,"TimeoutSeconds":0}}`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", content), `{"AppId":5,"Name":"test","Type":"test","Cluster":"test","Replicas":1,"ContainerName":"test","ContainerImage":"nginx","VersionTag":"test","Namespace":"test","Id":0,"Status":0,"Metrics":"","InitImage":"","CpuRequest":10,"CpuLimit":100,"MemRequest":100,"MemLimit":1000,"MeshEnabled":0,"ContainerPorts":[{"Port":80,"Type":"tcp","Alias":"别名","Brief":"描述"}],"Labels":[{"Key":"app","Value":"test"}],"NodeSelector":[{"Key":"group","Value":"app"}],"EnvReserve":[{"Key":"NODE_IP","Value":"status.hostIP"}],"EnvGlobal":[{"Type":"string","Key":"NUMBER","Value":"1","Brief":"数据数量"}],"EnvContainer":[{"Type":"string","Key":"NAME","Value":"john","Brief":"用户环境变量"}],"Mounts":[],"LivenessProbe":{"Type":"tcpSocket","Port":80,"Path":"","Brief":"存活探针","Period":5,"InitialDelay":10,"TimeoutSeconds":0},"ReadinessProbe":{"Type":"tcpSocket","Port":80,"Path":"","Brief":"就绪探针","Period":5,"InitialDelay":10,"TimeoutSeconds":0}}`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -324,10 +324,10 @@ func Test_Params_Parse_Attr_Pointer1(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.PostContent("/parse1", `{"id":1,"name":"john"}`), `1john`)
|
||||
t.Assert(client.PostContent("/parse2", `{"id":1,"name":"john"}`), `1john`)
|
||||
t.Assert(client.PostContent("/parse2?id=1&name=john"), `1john`)
|
||||
t.Assert(client.PostContent("/parse2", `id=1&name=john`), `1john`)
|
||||
t.Assert(client.PostContent(ctx, "/parse1", `{"id":1,"name":"john"}`), `1john`)
|
||||
t.Assert(client.PostContent(ctx, "/parse2", `{"id":1,"name":"john"}`), `1john`)
|
||||
t.Assert(client.PostContent(ctx, "/parse2?id=1&name=john"), `1john`)
|
||||
t.Assert(client.PostContent(ctx, "/parse2", `id=1&name=john`), `1john`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -353,8 +353,8 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.PostContent("/parse"), `The Id field is required`)
|
||||
t.Assert(client.PostContent("/parse?id=1"), `1`)
|
||||
t.Assert(client.PostContent(ctx, "/parse"), `The Id field is required`)
|
||||
t.Assert(client.PostContent(ctx, "/parse?id=1"), `1`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -385,7 +385,7 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
|
||||
// gtest.C(t, func(t *gtest.T) {
|
||||
// client := g.Client()
|
||||
// client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
// t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","scores":[[1,2,3]]}`), `1100`)
|
||||
// t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","scores":[[1,2,3]]}`), `1100`)
|
||||
// })
|
||||
//}
|
||||
|
||||
@ -448,13 +448,13 @@ func Test_Params_Struct(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent("/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent("/struct2", ``), ``)
|
||||
t.Assert(client.PostContent("/struct-valid", `id=1&name=john&password1=123&password2=0`), `The password2 value length must be between 2 and 20; 密码强度不足`)
|
||||
t.Assert(client.PostContent("/parse", `id=1&name=john&password1=123&password2=0`), `The password2 value length must be between 2 and 20; 密码强度不足`)
|
||||
t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.GetContent(ctx, "/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct2", ``), ``)
|
||||
t.Assert(client.PostContent(ctx, "/struct-valid", `id=1&name=john&password1=123&password2=0`), `The password2 value length must be between 2 and 20; 密码强度不足`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `id=1&name=john&password1=123&password2=0`), `The password2 value length must be between 2 and 20; 密码强度不足`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -484,7 +484,7 @@ func Test_Params_Structs(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.PostContent(
|
||||
t.Assert(client.PostContent(ctx,
|
||||
"/parse1",
|
||||
`[{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}, {"id":2,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}]`),
|
||||
`12`,
|
||||
@ -521,9 +521,9 @@ func Test_Params_Struct_Validation(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.GetContent("/", ``), `The Id field is required`)
|
||||
t.Assert(c.GetContent("/", `id=1&name=john`), `1john`)
|
||||
t.Assert(c.PostContent("/", `id=1&name=john&password1=123&password2=456`), `1john`)
|
||||
t.Assert(c.PostContent("/", `id=1`), `The name field is required`)
|
||||
t.Assert(c.GetContent(ctx, "/", ``), `The Id field is required`)
|
||||
t.Assert(c.GetContent(ctx, "/", `id=1&name=john`), `1john`)
|
||||
t.Assert(c.PostContent(ctx, "/", `id=1&name=john&password1=123&password2=456`), `1john`)
|
||||
t.Assert(c.PostContent(ctx, "/", `id=1`), `The name field is required`)
|
||||
})
|
||||
}
|
||||
|
@ -269,95 +269,95 @@ func Test_Params_Basic(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
// GET
|
||||
t.Assert(client.GetContent("/get", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.GetContent("/get", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.GetContent("/get", "bool=1"), `true`)
|
||||
t.Assert(client.GetContent("/get", "bool=0"), `false`)
|
||||
t.Assert(client.GetContent("/get", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.GetContent("/get", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.GetContent("/get", "int=-10000"), `-10000`)
|
||||
t.Assert(client.GetContent("/get", "int=10000"), `10000`)
|
||||
t.Assert(client.GetContent("/get", "uint=10000"), `10000`)
|
||||
t.Assert(client.GetContent("/get", "uint=9"), `9`)
|
||||
t.Assert(client.GetContent("/get", "string=key"), `key`)
|
||||
t.Assert(client.GetContent("/get", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.GetContent("/get", "a=1&b=2"), `1`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "bool=1"), `true`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "bool=0"), `false`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "int=-10000"), `-10000`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "int=10000"), `10000`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "uint=10000"), `10000`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "uint=9"), `9`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "string=key"), `key`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.GetContent(ctx, "/get", "a=1&b=2"), `1`)
|
||||
|
||||
// PUT
|
||||
t.Assert(client.PutContent("/put", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.PutContent("/put", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.PutContent("/put", "bool=1"), `true`)
|
||||
t.Assert(client.PutContent("/put", "bool=0"), `false`)
|
||||
t.Assert(client.PutContent("/put", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.PutContent("/put", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.PutContent("/put", "int=-10000"), `-10000`)
|
||||
t.Assert(client.PutContent("/put", "int=10000"), `10000`)
|
||||
t.Assert(client.PutContent("/put", "uint=10000"), `10000`)
|
||||
t.Assert(client.PutContent("/put", "uint=9"), `9`)
|
||||
t.Assert(client.PutContent("/put", "string=key"), `key`)
|
||||
t.Assert(client.PutContent("/put", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.PutContent("/put", "a=1&b=2"), `1`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "bool=1"), `true`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "bool=0"), `false`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "int=-10000"), `-10000`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "int=10000"), `10000`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "uint=10000"), `10000`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "uint=9"), `9`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "string=key"), `key`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.PutContent(ctx, "/put", "a=1&b=2"), `1`)
|
||||
|
||||
// DELETE
|
||||
t.Assert(client.DeleteContent("/delete", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.DeleteContent("/delete", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.DeleteContent("/delete", "bool=1"), `true`)
|
||||
t.Assert(client.DeleteContent("/delete", "bool=0"), `false`)
|
||||
t.Assert(client.DeleteContent("/delete", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.DeleteContent("/delete", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.DeleteContent("/delete", "int=-10000"), `-10000`)
|
||||
t.Assert(client.DeleteContent("/delete", "int=10000"), `10000`)
|
||||
t.Assert(client.DeleteContent("/delete", "uint=10000"), `10000`)
|
||||
t.Assert(client.DeleteContent("/delete", "uint=9"), `9`)
|
||||
t.Assert(client.DeleteContent("/delete", "string=key"), `key`)
|
||||
t.Assert(client.DeleteContent("/delete", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.DeleteContent("/delete", "a=1&b=2"), `1`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "bool=1"), `true`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "bool=0"), `false`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "int=-10000"), `-10000`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "int=10000"), `10000`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "uint=10000"), `10000`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "uint=9"), `9`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "string=key"), `key`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.DeleteContent(ctx, "/delete", "a=1&b=2"), `1`)
|
||||
|
||||
// PATCH
|
||||
t.Assert(client.PatchContent("/patch", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.PatchContent("/patch", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.PatchContent("/patch", "bool=1"), `true`)
|
||||
t.Assert(client.PatchContent("/patch", "bool=0"), `false`)
|
||||
t.Assert(client.PatchContent("/patch", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.PatchContent("/patch", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.PatchContent("/patch", "int=-10000"), `-10000`)
|
||||
t.Assert(client.PatchContent("/patch", "int=10000"), `10000`)
|
||||
t.Assert(client.PatchContent("/patch", "uint=10000"), `10000`)
|
||||
t.Assert(client.PatchContent("/patch", "uint=9"), `9`)
|
||||
t.Assert(client.PatchContent("/patch", "string=key"), `key`)
|
||||
t.Assert(client.PatchContent("/patch", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.PatchContent("/patch", "a=1&b=2"), `1`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "bool=1"), `true`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "bool=0"), `false`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "int=-10000"), `-10000`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "int=10000"), `10000`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "uint=10000"), `10000`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "uint=9"), `9`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "string=key"), `key`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.PatchContent(ctx, "/patch", "a=1&b=2"), `1`)
|
||||
|
||||
// Form
|
||||
t.Assert(client.PostContent("/form", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.PostContent("/form", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.PostContent("/form", "bool=1"), `true`)
|
||||
t.Assert(client.PostContent("/form", "bool=0"), `false`)
|
||||
t.Assert(client.PostContent("/form", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.PostContent("/form", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.PostContent("/form", "int=-10000"), `-10000`)
|
||||
t.Assert(client.PostContent("/form", "int=10000"), `10000`)
|
||||
t.Assert(client.PostContent("/form", "uint=10000"), `10000`)
|
||||
t.Assert(client.PostContent("/form", "uint=9"), `9`)
|
||||
t.Assert(client.PostContent("/form", "string=key"), `key`)
|
||||
t.Assert(client.PostContent("/form", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.PostContent("/form", "a=1&b=2"), `1`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "array[]=1&array[]=2"), `["1","2"]`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "slice=1&slice=2"), `2`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "bool=1"), `true`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "bool=0"), `false`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "float32=0.11"), `0.11`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "float64=0.22"), `0.22`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "int=-10000"), `-10000`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "int=10000"), `10000`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "uint=10000"), `10000`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "uint=9"), `9`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "string=key"), `key`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "map[a]=1&map[b]=2"), `2`)
|
||||
t.Assert(client.PostContent(ctx, "/form", "a=1&b=2"), `1`)
|
||||
|
||||
// Map
|
||||
t.Assert(client.GetContent("/map", "id=1&name=john"), `john`)
|
||||
t.Assert(client.PostContent("/map", "id=1&name=john"), `john`)
|
||||
t.Assert(client.GetContent(ctx, "/map", "id=1&name=john"), `john`)
|
||||
t.Assert(client.PostContent(ctx, "/map", "id=1&name=john"), `john`)
|
||||
|
||||
// Raw
|
||||
t.Assert(client.PutContent("/raw", "id=1&name=john"), `id=1&name=john`)
|
||||
t.Assert(client.PutContent(ctx, "/raw", "id=1&name=john"), `id=1&name=john`)
|
||||
|
||||
// Json
|
||||
t.Assert(client.PostContent("/json", `{"id":1, "name":"john"}`), `john`)
|
||||
t.Assert(client.PostContent(ctx, "/json", `{"id":1, "name":"john"}`), `john`)
|
||||
|
||||
// Struct
|
||||
t.Assert(client.GetContent("/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent("/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent("/struct-with-nil", ``), ``)
|
||||
t.Assert(client.PostContent("/struct-with-base", `id=1&name=john&password1=123&password2=456`), "1john1234561john")
|
||||
t.Assert(client.GetContent(ctx, "/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`)
|
||||
t.Assert(client.PostContent(ctx, "/struct-with-nil", ``), ``)
|
||||
t.Assert(client.PostContent(ctx, "/struct-with-base", `id=1&name=john&password1=123&password2=456`), "1john1234561john")
|
||||
})
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ func Test_Params_Header(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.Header(g.MapStrStr{"test": "123456"}).GetContent("/header"), "123456")
|
||||
t.Assert(client.Header(g.MapStrStr{"test": "123456"}).GetContent(ctx, "/header"), "123456")
|
||||
})
|
||||
}
|
||||
|
||||
@ -400,8 +400,8 @@ func Test_Params_SupportChars(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(c.PostContent("/form-value", "test-value=100"), "100")
|
||||
t.Assert(c.PostContent("/form-array", "test-array[]=1&test-array[]=2"), `["1","2"]`)
|
||||
t.Assert(c.PostContent(ctx, "/form-value", "test-value=100"), "100")
|
||||
t.Assert(c.PostContent(ctx, "/form-array", "test-array[]=1&test-array[]=2"), `["1","2"]`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -434,11 +434,11 @@ func Test_Params_Priority(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.GetContent("/query?a=1", "a=100"), "100")
|
||||
t.Assert(client.PostContent("/form?a=1", "a=100"), "100")
|
||||
t.Assert(client.PutContent("/form?a=1", "a=100"), "100")
|
||||
t.Assert(client.GetContent("/request?a=1", "a=100"), "100")
|
||||
t.Assert(client.GetContent("/request-map?a=1&b=2&c=3", "a=100&b=200&c=300"), `{"a":"100","b":"200"}`)
|
||||
t.Assert(client.GetContent(ctx, "/query?a=1", "a=100"), "100")
|
||||
t.Assert(client.PostContent(ctx, "/form?a=1", "a=100"), "100")
|
||||
t.Assert(client.PutContent(ctx, "/form?a=1", "a=100"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/request?a=1", "a=100"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/request-map?a=1&b=2&c=3", "a=100&b=200&c=300"), `{"a":"100","b":"200"}`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -460,7 +460,7 @@ func Test_Params_GetRequestMap(t *testing.T) {
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(
|
||||
client.PostContent(
|
||||
client.PostContent(ctx,
|
||||
"/map",
|
||||
"time_end2020-04-18 16:11:58&returnmsg=Success&attach=",
|
||||
),
|
||||
@ -496,7 +496,7 @@ func Test_Params_Modify(t *testing.T) {
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(
|
||||
client.PostContent(
|
||||
client.PostContent(ctx,
|
||||
"/param/modify",
|
||||
`{"id":1}`,
|
||||
),
|
||||
@ -530,9 +530,9 @@ func Test_Params_Parse_DefaultValueTag(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.PostContent("/parse"), `{"Name":"john","Score":60}`)
|
||||
t.Assert(client.PostContent("/parse", `{"name":"smith"}`), `{"Name":"smith","Score":60}`)
|
||||
t.Assert(client.PostContent("/parse", `{"name":"smith", "score":100}`), `{"Name":"smith","Score":100}`)
|
||||
t.Assert(client.PostContent(ctx, "/parse"), `{"Name":"john","Score":60}`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"name":"smith"}`), `{"Name":"smith","Score":60}`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", `{"name":"smith", "score":100}`), `{"Name":"smith","Score":100}`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -564,10 +564,10 @@ func Test_Params_Parse_Validation(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.GetContent("/parse"), `请输入账号; 账号长度为6到30位; 请输入密码; 密码长度不够; 请确认密码; 密码长度不够; 两次密码不一致`)
|
||||
t.Assert(client.GetContent("/parse?name=john11&password1=123456&password2=123"), `密码长度不够; 两次密码不一致`)
|
||||
t.Assert(client.GetContent("/parse?name=john&password1=123456&password2=123456"), `账号长度为6到30位`)
|
||||
t.Assert(client.GetContent("/parse?name=john11&password1=123456&password2=123456"), `ok`)
|
||||
t.Assert(client.GetContent(ctx, "/parse"), `请输入账号; 账号长度为6到30位; 请输入密码; 密码长度不够; 请确认密码; 密码长度不够; 两次密码不一致`)
|
||||
t.Assert(client.GetContent(ctx, "/parse?name=john11&password1=123456&password2=123"), `密码长度不够; 两次密码不一致`)
|
||||
t.Assert(client.GetContent(ctx, "/parse?name=john&password1=123456&password2=123456"), `账号长度为6到30位`)
|
||||
t.Assert(client.GetContent(ctx, "/parse?name=john11&password1=123456&password2=123456"), `ok`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -610,7 +610,7 @@ func Test_Params_Parse_EmbeddedWithAliasName1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.GetContent("/parse?cate=1&page=2&size=10"), `{"Type":"","CategoryId":0,"Page":2,"Size":10,"Sort":0,"UserId":0}`)
|
||||
t.Assert(client.GetContent(ctx, "/parse?cate=1&page=2&size=10"), `{"Type":"","CategoryId":0,"Page":2,"Size":10,"Sort":0,"UserId":0}`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -653,6 +653,6 @@ func Test_Params_Parse_EmbeddedWithAliasName2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(prefix)
|
||||
|
||||
t.Assert(client.GetContent("/parse?cate=1&page=2&size=10"), `{"Type":"","CategoryId":1,"Page":2,"Size":10,"Sort":0,"UserId":0}`)
|
||||
t.Assert(client.GetContent(ctx, "/parse?cate=1&page=2&size=10"), `{"Type":"","CategoryId":1,"Page":2,"Size":10,"Sort":0,"UserId":0}`)
|
||||
})
|
||||
}
|
||||
|
@ -55,11 +55,11 @@ func Test_Params_Xml_Request(t *testing.T) {
|
||||
|
||||
content1 := `<doc><id>1</id><name>john</name><password1>123Abc!@#</password1><password2>123Abc!@#</password2></doc>`
|
||||
content2 := `<doc><id>1</id><name>john</name><password1>123Abc!@#</password1><password2>123</password2></doc>`
|
||||
t.Assert(client.GetContent("/get", content1), ``)
|
||||
t.Assert(client.PostContent("/get", content1), `1john`)
|
||||
t.Assert(client.GetContent("/map", content1), ``)
|
||||
t.Assert(client.PostContent("/map", content1), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.PostContent("/parse", content1), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.PostContent("/parse", content2), `密码强度不足; 两次密码不一致`)
|
||||
t.Assert(client.GetContent(ctx, "/get", content1), ``)
|
||||
t.Assert(client.PostContent(ctx, "/get", content1), `1john`)
|
||||
t.Assert(client.GetContent(ctx, "/map", content1), ``)
|
||||
t.Assert(client.PostContent(ctx, "/map", content1), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", content1), `1john123Abc!@#123Abc!@#`)
|
||||
t.Assert(client.PostContent(ctx, "/parse", content2), `密码强度不足; 两次密码不一致`)
|
||||
})
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ func Test_Router_Basic1(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/john"), "")
|
||||
t.Assert(client.GetContent("/john/update"), "john")
|
||||
t.Assert(client.GetContent("/john/edit"), "edit")
|
||||
t.Assert(client.GetContent("/user/list/100.html"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/john"), "")
|
||||
t.Assert(client.GetContent(ctx, "/john/update"), "john")
|
||||
t.Assert(client.GetContent(ctx, "/john/edit"), "edit")
|
||||
t.Assert(client.GetContent(ctx, "/user/list/100.html"), "100")
|
||||
})
|
||||
}
|
||||
|
||||
@ -68,8 +68,8 @@ func Test_Router_Basic2(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/data"), "data")
|
||||
t.Assert(client.GetContent("/data.json"), "json")
|
||||
t.Assert(client.GetContent(ctx, "/data"), "data")
|
||||
t.Assert(client.GetContent(ctx, "/data.json"), "json")
|
||||
})
|
||||
}
|
||||
|
||||
@ -94,9 +94,9 @@ func Test_Router_Value(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/data"), "data")
|
||||
t.Assert(client.GetContent("/data.json"), "json")
|
||||
t.Assert(client.GetContent("/data.json.map"), "json")
|
||||
t.Assert(client.GetContent(ctx, "/data"), "data")
|
||||
t.Assert(client.GetContent(ctx, "/data.json"), "json")
|
||||
t.Assert(client.GetContent(ctx, "/data.json.map"), "json")
|
||||
})
|
||||
}
|
||||
|
||||
@ -120,22 +120,22 @@ func Test_Router_Method(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
resp1, err := client.Get("/get")
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Post("/get")
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get("/post")
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post("/post")
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 200)
|
||||
@ -161,12 +161,12 @@ func Test_Router_ExtraChar(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/api/test"), "test")
|
||||
t.Assert(client.GetContent("/api/test/"), "test")
|
||||
t.Assert(client.GetContent("/api/test//"), "test")
|
||||
t.Assert(client.GetContent("//api/test//"), "test")
|
||||
t.Assert(client.GetContent("//api//test//"), "test")
|
||||
t.Assert(client.GetContent("///api///test///"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/api/test"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/api/test/"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/api/test//"), "test")
|
||||
t.Assert(client.GetContent(ctx, "//api/test//"), "test")
|
||||
t.Assert(client.GetContent(ctx, "//api//test//"), "test")
|
||||
t.Assert(client.GetContent(ctx, "///api///test///"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -196,27 +196,27 @@ func Test_Router_Status(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
resp1, err := client.Get("/200")
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Get("/300")
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 300)
|
||||
|
||||
resp3, err := client.Get("/400")
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 400)
|
||||
|
||||
resp4, err := client.Get("/500")
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 500)
|
||||
|
||||
resp5, err := client.Get("/404")
|
||||
resp5, err := client.Get(ctx, "/404")
|
||||
defer resp5.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp5.StatusCode, 404)
|
||||
@ -242,8 +242,8 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "hello")
|
||||
resp, err := client.Get("/ThisDoesNotExist")
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
resp, err := client.Get(ctx, "/ThisDoesNotExist")
|
||||
defer resp.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
@ -268,8 +268,8 @@ func Test_Router_404(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "hello")
|
||||
resp, err := client.Get("/ThisDoesNotExist")
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
resp, err := client.Get(ctx, "/ThisDoesNotExist")
|
||||
defer resp.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
@ -301,9 +301,9 @@ func Test_Router_Priority(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/admin"), "admin")
|
||||
t.Assert(client.GetContent("/admin-1"), "admin-{page}")
|
||||
t.Assert(client.GetContent("/admin-goods"), "admin-goods")
|
||||
t.Assert(client.GetContent("/admin-goods-2"), "admin-goods-{page}")
|
||||
t.Assert(client.GetContent(ctx, "/admin"), "admin")
|
||||
t.Assert(client.GetContent(ctx, "/admin-1"), "admin-{page}")
|
||||
t.Assert(client.GetContent(ctx, "/admin-goods"), "admin-goods")
|
||||
t.Assert(client.GetContent(ctx, "/admin-goods-2"), "admin-goods-{page}")
|
||||
})
|
||||
}
|
||||
|
@ -45,26 +45,26 @@ func Test_Router_DomainBasic(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/john"), "Not Found")
|
||||
t.Assert(client.GetContent("/john/update"), "Not Found")
|
||||
t.Assert(client.GetContent("/john/edit"), "Not Found")
|
||||
t.Assert(client.GetContent("/user/list/100.html"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/john"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/john/update"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/john/edit"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/user/list/100.html"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
t.Assert(client.GetContent("/john"), "")
|
||||
t.Assert(client.GetContent("/john/update"), "john")
|
||||
t.Assert(client.GetContent("/john/edit"), "edit")
|
||||
t.Assert(client.GetContent("/user/list/100.html"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/john"), "")
|
||||
t.Assert(client.GetContent(ctx, "/john/update"), "john")
|
||||
t.Assert(client.GetContent(ctx, "/john/edit"), "edit")
|
||||
t.Assert(client.GetContent(ctx, "/user/list/100.html"), "100")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
t.Assert(client.GetContent("/john"), "")
|
||||
t.Assert(client.GetContent("/john/update"), "john")
|
||||
t.Assert(client.GetContent("/john/edit"), "edit")
|
||||
t.Assert(client.GetContent("/user/list/100.html"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/john"), "")
|
||||
t.Assert(client.GetContent(ctx, "/john/update"), "john")
|
||||
t.Assert(client.GetContent(ctx, "/john/edit"), "edit")
|
||||
t.Assert(client.GetContent(ctx, "/user/list/100.html"), "100")
|
||||
})
|
||||
}
|
||||
|
||||
@ -88,22 +88,22 @@ func Test_Router_DomainMethod(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
resp1, err := client.Get("/get")
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 404)
|
||||
|
||||
resp2, err := client.Post("/get")
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get("/post")
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post("/post")
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 404)
|
||||
@ -113,22 +113,22 @@ func Test_Router_DomainMethod(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
resp1, err := client.Get("/get")
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Post("/get")
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get("/post")
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post("/post")
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 200)
|
||||
@ -138,22 +138,22 @@ func Test_Router_DomainMethod(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
resp1, err := client.Get("/get")
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Post("/get")
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get("/post")
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post("/post")
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 200)
|
||||
@ -186,22 +186,22 @@ func Test_Router_DomainStatus(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
resp1, err := client.Get("/200")
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 404)
|
||||
|
||||
resp2, err := client.Get("/300")
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get("/400")
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Get("/500")
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 404)
|
||||
@ -210,22 +210,22 @@ func Test_Router_DomainStatus(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
resp1, err := client.Get("/200")
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Get("/300")
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 300)
|
||||
|
||||
resp3, err := client.Get("/400")
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 400)
|
||||
|
||||
resp4, err := client.Get("/500")
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 500)
|
||||
@ -234,22 +234,22 @@ func Test_Router_DomainStatus(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
resp1, err := client.Get("/200")
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Get("/300")
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.StatusCode, 300)
|
||||
|
||||
resp3, err := client.Get("/400")
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp3.StatusCode, 400)
|
||||
|
||||
resp4, err := client.Get("/500")
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp4.StatusCode, 500)
|
||||
@ -276,22 +276,22 @@ func Test_Router_DomainCustomStatusHandler(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "hello")
|
||||
t.Assert(client.GetContent("/ThisDoesNotExist"), "404 page")
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
t.Assert(client.GetContent(ctx, "/ThisDoesNotExist"), "404 page")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "hello")
|
||||
t.Assert(client.GetContent("/ThisDoesNotExist"), "404 page")
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
t.Assert(client.GetContent(ctx, "/ThisDoesNotExist"), "404 page")
|
||||
})
|
||||
}
|
||||
|
||||
@ -312,19 +312,19 @@ func Test_Router_Domain404(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "hello")
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "hello")
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
})
|
||||
}
|
||||
|
||||
@ -361,16 +361,16 @@ func Test_Router_DomainGroup(t *testing.T) {
|
||||
client2 := g.Client()
|
||||
client2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client1.GetContent("/app/t/list/2.html"), "t&2")
|
||||
t.Assert(client2.GetContent("/app/t/list/2.html"), "Not Found")
|
||||
t.Assert(client1.GetContent(ctx, "/app/t/list/2.html"), "t&2")
|
||||
t.Assert(client2.GetContent(ctx, "/app/t/list/2.html"), "Not Found")
|
||||
|
||||
t.Assert(client1.GetContent("/app/order/info/2"), "2")
|
||||
t.Assert(client2.GetContent("/app/order/info/2"), "Not Found")
|
||||
t.Assert(client1.GetContent(ctx, "/app/order/info/2"), "2")
|
||||
t.Assert(client2.GetContent(ctx, "/app/order/info/2"), "Not Found")
|
||||
|
||||
t.Assert(client1.GetContent("/app/comment/20"), "Not Found")
|
||||
t.Assert(client2.GetContent("/app/comment/20"), "Not Found")
|
||||
t.Assert(client1.GetContent(ctx, "/app/comment/20"), "Not Found")
|
||||
t.Assert(client2.GetContent(ctx, "/app/comment/20"), "Not Found")
|
||||
|
||||
t.Assert(client1.DeleteContent("/app/comment/20"), "20")
|
||||
t.Assert(client2.DeleteContent("/app/comment/20"), "Not Found")
|
||||
t.Assert(client1.DeleteContent(ctx, "/app/comment/20"), "20")
|
||||
t.Assert(client2.DeleteContent(ctx, "/app/comment/20"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
@ -69,54 +69,54 @@ func Test_Router_DomainObjectRest(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.PutContent("/"), "Not Found")
|
||||
t.Assert(client.PostContent("/"), "Not Found")
|
||||
t.Assert(client.DeleteContent("/"), "Not Found")
|
||||
t.Assert(client.PatchContent("/"), "Not Found")
|
||||
t.Assert(client.OptionsContent("/"), "Not Found")
|
||||
resp1, err := client.Head("/")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.PutContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.PostContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.PatchContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.OptionsContent(ctx, "/"), "Not Found")
|
||||
resp1, err := client.Head(ctx, "/")
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/"), "1Object Options2")
|
||||
resp1, err := client.Head("/")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/"), "1Object Options2")
|
||||
resp1, err := client.Head(ctx, "/")
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "1")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/"), "1Object Options2")
|
||||
resp1, err := client.Head("/")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/"), "1Object Options2")
|
||||
resp1, err := client.Head(ctx, "/")
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "1")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
@ -52,38 +52,38 @@ func Test_Router_DomainObject1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/show"), "Not Found")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/show"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -101,40 +101,40 @@ func Test_Router_DomainObject2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/object/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/object/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -152,42 +152,42 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent("/object-info"), "Not Found")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object-info"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent("/object-info"), "1Object Info2")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object-info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://local:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent("/object-info"), "1Object Info2")
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object-info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ func Test_Router_Exit(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "123")
|
||||
t.Assert(client.GetContent("/test/test"), "1test-start23")
|
||||
t.Assert(client.GetContent(ctx, "/"), "123")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "1test-start23")
|
||||
})
|
||||
}
|
||||
|
||||
@ -78,8 +78,8 @@ func Test_Router_ExitHook(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/priority/show"), "3show")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/priority/show"), "3show")
|
||||
})
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ func Test_Router_ExitAll(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/priority/show"), "3")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/priority/show"), "3")
|
||||
})
|
||||
}
|
||||
|
@ -66,19 +66,19 @@ func Test_Router_Group_Group(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/api.v2"), "Not Found")
|
||||
t.Assert(client.GetContent("/api.v2/test"), "1test2")
|
||||
t.Assert(client.GetContent("/api.v2/hook"), "hook any")
|
||||
t.Assert(client.GetContent("/api.v2/hook/name"), "hook namehook any")
|
||||
t.Assert(client.GetContent("/api.v2/hook/name/any"), "hook any")
|
||||
t.Assert(client.GetContent("/api.v2/order/list"), "1list2")
|
||||
t.Assert(client.GetContent("/api.v2/order/update"), "Not Found")
|
||||
t.Assert(client.PutContent("/api.v2/order/update"), "1update2")
|
||||
t.Assert(client.GetContent("/api.v2/user/drop"), "Not Found")
|
||||
t.Assert(client.DeleteContent("/api.v2/user/drop"), "1drop2")
|
||||
t.Assert(client.GetContent("/api.v2/user/edit"), "Not Found")
|
||||
t.Assert(client.PostContent("/api.v2/user/edit"), "1edit2")
|
||||
t.Assert(client.GetContent("/api.v2/user/info"), "1info2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/test"), "1test2")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/hook"), "hook any")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/hook/name"), "hook namehook any")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/hook/name/any"), "hook any")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/order/list"), "1list2")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/order/update"), "Not Found")
|
||||
t.Assert(client.PutContent(ctx, "/api.v2/order/update"), "1update2")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/user/drop"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/api.v2/user/drop"), "1drop2")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/user/edit"), "Not Found")
|
||||
t.Assert(client.PostContent(ctx, "/api.v2/user/edit"), "1edit2")
|
||||
t.Assert(client.GetContent(ctx, "/api.v2/user/info"), "1info2")
|
||||
})
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ func Test_Router_Group_Hook1(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/api/handler"), "012")
|
||||
t.Assert(client.PostContent("/api/handler"), "02")
|
||||
t.Assert(client.GetContent("/api/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api/handler"), "012")
|
||||
t.Assert(client.PostContent(ctx, "/api/handler"), "02")
|
||||
t.Assert(client.GetContent(ctx, "/api/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -68,10 +68,10 @@ func Test_Router_Group_Hook2(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/api/handler"), "012")
|
||||
t.Assert(client.PostContent("/api/handler"), "Not Found")
|
||||
t.Assert(client.GetContent("/api/ThisDoesNotExist"), "02")
|
||||
t.Assert(client.PostContent("/api/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api/handler"), "012")
|
||||
t.Assert(client.PostContent(ctx, "/api/handler"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api/ThisDoesNotExist"), "02")
|
||||
t.Assert(client.PostContent(ctx, "/api/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -99,8 +99,8 @@ func Test_Router_Group_Hook3(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/api/handler"), "012")
|
||||
t.Assert(client.PostContent("/api/handler"), "012")
|
||||
t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "02")
|
||||
t.Assert(client.GetContent(ctx, "/api/handler"), "012")
|
||||
t.Assert(client.PostContent(ctx, "/api/handler"), "012")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/ThisDoesNotExist"), "02")
|
||||
})
|
||||
}
|
||||
|
@ -72,27 +72,27 @@ func Test_Router_GroupRest1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/api/obj"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/api/obj"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/api/obj"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/api/obj"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/api/obj"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/api/obj"), "1Object Options2")
|
||||
resp2, err := client.Head("/api/obj")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/api/obj"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/api/obj"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/obj"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/api/obj"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/api/obj"), "1Object Options2")
|
||||
resp2, err := client.Head(ctx, "/api/obj")
|
||||
if err == nil {
|
||||
defer resp2.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.Header.Get("head-ok"), "1")
|
||||
|
||||
t.Assert(client.GetContent("/api/group-obj-rest"), "Not Found")
|
||||
t.Assert(client.GetContent("/api/group-obj-rest/get"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/api/group-obj-rest/put"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/api/group-obj-rest/post"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/api/group-obj-rest/delete"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/api/group-obj-rest/patch"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/api/group-obj-rest/options"), "1Object Options2")
|
||||
resp4, err := client.Head("/api/group-obj-rest/head")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-obj-rest"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-obj-rest/get"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/api/group-obj-rest/put"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/api/group-obj-rest/post"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/group-obj-rest/delete"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/api/group-obj-rest/patch"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/api/group-obj-rest/options"), "1Object Options2")
|
||||
resp4, err := client.Head(ctx, "/api/group-obj-rest/head")
|
||||
if err == nil {
|
||||
defer resp4.Close()
|
||||
}
|
||||
@ -119,27 +119,27 @@ func Test_Router_GroupRest2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/api/obj"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/api/obj"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/api/obj"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/api/obj"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/api/obj"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/api/obj"), "1Object Options2")
|
||||
resp2, err := client.Head("/api/obj")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/api/obj"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/api/obj"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/obj"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/api/obj"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/api/obj"), "1Object Options2")
|
||||
resp2, err := client.Head(ctx, "/api/obj")
|
||||
if err == nil {
|
||||
defer resp2.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.Header.Get("head-ok"), "1")
|
||||
|
||||
t.Assert(client.GetContent("/api/group-obj-rest"), "Not Found")
|
||||
t.Assert(client.GetContent("/api/group-obj-rest/get"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/api/group-obj-rest/put"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/api/group-obj-rest/post"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/api/group-obj-rest/delete"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/api/group-obj-rest/patch"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/api/group-obj-rest/options"), "1Object Options2")
|
||||
resp4, err := client.Head("/api/group-obj-rest/head")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-obj-rest"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-obj-rest/get"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/api/group-obj-rest/put"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/api/group-obj-rest/post"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/group-obj-rest/delete"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/api/group-obj-rest/patch"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/api/group-obj-rest/options"), "1Object Options2")
|
||||
resp4, err := client.Head(ctx, "/api/group-obj-rest/head")
|
||||
if err == nil {
|
||||
defer resp4.Close()
|
||||
}
|
||||
|
@ -63,18 +63,18 @@ func Test_Router_GroupBasic1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/api/handler"), "Handler")
|
||||
t.Assert(client.GetContent(ctx, "/api/handler"), "Handler")
|
||||
|
||||
t.Assert(client.GetContent("/api/obj"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/api/obj/"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/api/obj/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/api/obj/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent("/api/obj/my-show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/api/obj/show"), "1Object Show2")
|
||||
t.Assert(client.DeleteContent("/api/obj/rest"), "1Object Delete2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/my-show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/show"), "1Object Show2")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/obj/rest"), "1Object Delete2")
|
||||
|
||||
t.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -99,15 +99,15 @@ func Test_Router_GroupBasic2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/api/handler"), "Handler")
|
||||
t.Assert(client.GetContent(ctx, "/api/handler"), "Handler")
|
||||
|
||||
t.Assert(client.GetContent("/api/obj/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent("/api/obj/my-show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/api/obj/show"), "1Object Show2")
|
||||
t.Assert(client.DeleteContent("/api/obj/rest"), "1Object Delete2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/my-show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/api/obj/show"), "1Object Show2")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/obj/rest"), "1Object Delete2")
|
||||
|
||||
t.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -128,12 +128,12 @@ func Test_Router_GroupBuildInVar(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/api/group-object/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/api/group-object/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent("/api/group-object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-object/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-object/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent(ctx, "/api/group-object/show"), "1Object Show2")
|
||||
|
||||
t.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/ThisDoesNotExist"), "Not Found")
|
||||
t.Assert(client.DeleteContent(ctx, "/api/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -152,8 +152,8 @@ func Test_Router_Group_Methods(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/obj/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/obj/delete"), "1Object Delete2")
|
||||
t.Assert(client.GetContent(ctx, "/obj/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/obj/delete"), "1Object Delete2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -187,8 +187,8 @@ func Test_Router_Group_MultiServer(t *testing.T) {
|
||||
c1.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p1))
|
||||
c2 := g.Client()
|
||||
c2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p2))
|
||||
t.Assert(c1.PostContent("/post"), "post1")
|
||||
t.Assert(c2.PostContent("/post"), "post2")
|
||||
t.Assert(c1.PostContent(ctx, "/post"), "post1")
|
||||
t.Assert(c2.PostContent(ctx, "/post"), "post2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ func Test_Router_Group_Map(t *testing.T) {
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(c.GetContent("/test"), "get")
|
||||
t.Assert(c.PostContent("/test"), "post")
|
||||
t.Assert(c.GetContent(ctx, "/test"), "get")
|
||||
t.Assert(c.PostContent(ctx, "/test"), "post")
|
||||
})
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func Test_Router_Handler_Extended_Handler_Basic(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/test"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ func Test_Router_Handler_Extended_Handler_WithObject(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/test?age=18&name=john"), `{"code":0,"message":"","data":{"Id":1,"Age":18,"Name":"john"}}`)
|
||||
t.Assert(client.GetContent("/test/error"), `{"code":50,"message":"error","data":null}`)
|
||||
t.Assert(client.GetContent(ctx, "/test?age=18&name=john"), `{"code":0,"message":"","data":{"Id":1,"Age":18,"Name":"john"}}`)
|
||||
t.Assert(client.GetContent(ctx, "/test/error"), `{"code":50,"message":"error","data":null}`)
|
||||
})
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ func Test_Router_Hook_Basic(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "123")
|
||||
t.Assert(client.GetContent("/test/test"), "1test23")
|
||||
t.Assert(client.GetContent(ctx, "/"), "123")
|
||||
t.Assert(client.GetContent(ctx, "/test/test"), "1test23")
|
||||
})
|
||||
}
|
||||
|
||||
@ -79,11 +79,11 @@ func Test_Router_Hook_Fuzzy_Router(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/john"), "Not Found")
|
||||
t.Assert(client.GetContent("/john/info"), "1000")
|
||||
t.Assert(client.GetContent("/john/info"), "1001")
|
||||
t.Assert(client.GetContent("/john/list/1.java"), "john&1&1002")
|
||||
t.Assert(client.GetContent("/john/list/2.java"), "john&2&1002")
|
||||
t.Assert(client.GetContent(ctx, "/john"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/john/info"), "1000")
|
||||
t.Assert(client.GetContent(ctx, "/john/info"), "1001")
|
||||
t.Assert(client.GetContent(ctx, "/john/list/1.java"), "john&1&1002")
|
||||
t.Assert(client.GetContent(ctx, "/john/list/2.java"), "john&2&1002")
|
||||
})
|
||||
}
|
||||
|
||||
@ -119,10 +119,10 @@ func Test_Router_Hook_Priority(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/priority/show"), "312show")
|
||||
t.Assert(client.GetContent("/priority/any/any"), "2")
|
||||
t.Assert(client.GetContent("/priority/name"), "12")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/priority/show"), "312show")
|
||||
t.Assert(client.GetContent(ctx, "/priority/any/any"), "2")
|
||||
t.Assert(client.GetContent(ctx, "/priority/name"), "12")
|
||||
})
|
||||
}
|
||||
|
||||
@ -153,8 +153,8 @@ func Test_Router_Hook_Multi(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/multi-hook"), "12show")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/multi-hook"), "12show")
|
||||
})
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ func Test_Router_Hook_ExitAll(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/test"), "test")
|
||||
t.Assert(client.GetContent("/hook/test"), "hook")
|
||||
t.Assert(client.GetContent(ctx, "/test"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/hook/test"), "hook")
|
||||
})
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ func Test_NameToUri_FullName(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent("/NamesObject/ShowName"), "Object Show Name")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/NamesObject/ShowName"), "Object Show Name")
|
||||
})
|
||||
}
|
||||
|
||||
@ -58,9 +58,9 @@ func Test_NameToUri_AllLower(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent("/namesobject/showname"), "Object Show Name")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/namesobject/showname"), "Object Show Name")
|
||||
})
|
||||
}
|
||||
|
||||
@ -79,9 +79,9 @@ func Test_NameToUri_Camel(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent("/namesObject/showName"), "Object Show Name")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/namesObject/showName"), "Object Show Name")
|
||||
})
|
||||
}
|
||||
|
||||
@ -100,8 +100,8 @@ func Test_NameToUri_Default(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent("/names-object/show-name"), "Object Show Name")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/names-object/show-name"), "Object Show Name")
|
||||
})
|
||||
}
|
||||
|
@ -69,32 +69,32 @@ func Test_Router_ObjectRest(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/"), "1Object Options2")
|
||||
resp1, err := client.Head("/")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/"), "1Object Options2")
|
||||
resp1, err := client.Head(ctx, "/")
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "1")
|
||||
|
||||
t.Assert(client.GetContent("/object-rest/get"), "1Object Get2")
|
||||
t.Assert(client.PutContent("/object-rest/put"), "1Object Put2")
|
||||
t.Assert(client.PostContent("/object-rest/post"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent("/object-rest/delete"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent("/object-rest/patch"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent("/object-rest/options"), "1Object Options2")
|
||||
resp2, err := client.Head("/object-rest/head")
|
||||
t.Assert(client.GetContent(ctx, "/object-rest/get"), "1Object Get2")
|
||||
t.Assert(client.PutContent(ctx, "/object-rest/put"), "1Object Put2")
|
||||
t.Assert(client.PostContent(ctx, "/object-rest/post"), "1Object Post2")
|
||||
t.Assert(client.DeleteContent(ctx, "/object-rest/delete"), "1Object Delete2")
|
||||
t.Assert(client.PatchContent(ctx, "/object-rest/patch"), "1Object Patch2")
|
||||
t.Assert(client.OptionsContent(ctx, "/object-rest/options"), "1Object Options2")
|
||||
resp2, err := client.Head(ctx, "/object-rest/head")
|
||||
if err == nil {
|
||||
defer resp2.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.Assert(resp2.Header.Get("head-ok"), "1")
|
||||
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ func Test_Router_ObjectRest_Id(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/object/99"), "1Object Get992")
|
||||
t.Assert(client.PutContent("/object/99"), "1Object Put992")
|
||||
t.Assert(client.PostContent("/object/99"), "1Object Post992")
|
||||
t.Assert(client.DeleteContent("/object/99"), "1Object Delete992")
|
||||
t.Assert(client.GetContent(ctx, "/object/99"), "1Object Get992")
|
||||
t.Assert(client.PutContent(ctx, "/object/99"), "1Object Put992")
|
||||
t.Assert(client.PostContent(ctx, "/object/99"), "1Object Post992")
|
||||
t.Assert(client.DeleteContent(ctx, "/object/99"), "1Object Delete992")
|
||||
})
|
||||
}
|
||||
|
@ -53,19 +53,19 @@ func Test_Router_Object1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/show"), "1Object Show2")
|
||||
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent("/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "1Object Index2")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "1Object Show2")
|
||||
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -83,15 +83,15 @@ func Test_Router_Object2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent("/object/info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "1Object Show2")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "1Object Info2")
|
||||
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,15 +109,15 @@ func Test_Router_ObjectMethod(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/object"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent("/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent("/object-info"), "1Object Info2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/init"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/shut"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/index"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/show"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object/info"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/object-info"), "1Object Info2")
|
||||
|
||||
t.Assert(client.GetContent("/none-exist"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ func Test_Server_Wrap_Handler(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d/api", p))
|
||||
|
||||
response, er1 := client.Get("/wrapf")
|
||||
response, er1 := client.Get(ctx, "/wrapf")
|
||||
defer response.Close()
|
||||
t.Assert(er1, nil)
|
||||
t.Assert(response.StatusCode, http.StatusBadRequest)
|
||||
t.Assert(response.ReadAllString(), str1)
|
||||
|
||||
response2, er2 := client.Post("/wraph")
|
||||
response2, er2 := client.Post(ctx, "/wraph")
|
||||
defer response2.Close()
|
||||
t.Assert(er2, nil)
|
||||
t.Assert(response2.StatusCode, http.StatusInternalServerError)
|
||||
|
@ -41,25 +41,25 @@ func Test_Session_Cookie(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetBrowserMode(true)
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
r1, e1 := client.Get("/set?k=key1&v=100")
|
||||
r1, e1 := client.Get(ctx, "/set?k=key1&v=100")
|
||||
if r1 != nil {
|
||||
defer r1.Close()
|
||||
}
|
||||
t.Assert(e1, nil)
|
||||
t.Assert(r1.ReadAllString(), "")
|
||||
|
||||
t.Assert(client.GetContent("/set?k=key2&v=200"), "")
|
||||
t.Assert(client.GetContent(ctx, "/set?k=key2&v=200"), "")
|
||||
|
||||
t.Assert(client.GetContent("/get?k=key1"), "100")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent("/get?k=key3"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key1"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key3"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key4"), "")
|
||||
t.Assert(client.GetContent("/get?k=key1"), "")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent("/clear"), "")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key3"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key3"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key4"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/clear"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "")
|
||||
})
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ func Test_Session_Header(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
response, e1 := client.Get("/set?k=key1&v=100")
|
||||
response, e1 := client.Get(ctx, "/set?k=key1&v=100")
|
||||
if response != nil {
|
||||
defer response.Close()
|
||||
}
|
||||
@ -98,18 +98,18 @@ func Test_Session_Header(t *testing.T) {
|
||||
|
||||
client.SetHeader(s.GetSessionIdName(), sessionId)
|
||||
|
||||
t.Assert(client.GetContent("/set?k=key2&v=200"), "")
|
||||
t.Assert(client.GetContent(ctx, "/set?k=key2&v=200"), "")
|
||||
|
||||
t.Assert(client.GetContent("/get?k=key1"), "100")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent("/get?k=key3"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key1"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key3"), "")
|
||||
t.Assert(client.GetContent("/remove?k=key4"), "")
|
||||
t.Assert(client.GetContent("/get?k=key1"), "")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent("/clear"), "")
|
||||
t.Assert(client.GetContent("/get?k=key2"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key3"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key3"), "")
|
||||
t.Assert(client.GetContent(ctx, "/remove?k=key4"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "200")
|
||||
t.Assert(client.GetContent(ctx, "/clear"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key2"), "")
|
||||
})
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ func Test_Session_StorageFile(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
response, e1 := client.Get("/set?k=key&v=100")
|
||||
response, e1 := client.Get(ctx, "/set?k=key&v=100")
|
||||
if response != nil {
|
||||
defer response.Close()
|
||||
}
|
||||
@ -148,8 +148,8 @@ func Test_Session_StorageFile(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader(s.GetSessionIdName(), sessionId)
|
||||
t.Assert(client.GetContent("/get?k=key"), "100")
|
||||
t.Assert(client.GetContent("/get?k=key1"), "")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key"), "100")
|
||||
t.Assert(client.GetContent(ctx, "/get?k=key1"), "")
|
||||
})
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ func Test_Session_Custom_Id(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
r, err := client.Get("/id")
|
||||
r, err := client.Get(ctx, "/id")
|
||||
t.Assert(err, nil)
|
||||
defer r.Close()
|
||||
t.Assert(r.ReadAllString(), sessionId)
|
||||
@ -193,6 +193,6 @@ func Test_Session_Custom_Id(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
client.SetHeader(s.GetSessionIdName(), sessionId)
|
||||
t.Assert(client.GetContent("/value"), value)
|
||||
t.Assert(client.GetContent(ctx, "/value"), value)
|
||||
})
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ func Test_Static_ServerRoot(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "index")
|
||||
t.Assert(client.GetContent("/index.htm"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/index.htm"), "index")
|
||||
})
|
||||
|
||||
// SetServerRoot with relative path
|
||||
@ -56,8 +56,8 @@ func Test_Static_ServerRoot(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "index")
|
||||
t.Assert(client.GetContent("/index.htm"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/index.htm"), "index")
|
||||
})
|
||||
}
|
||||
|
||||
@ -73,12 +73,12 @@ func Test_Static_ServerRoot_Security(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "index")
|
||||
t.Assert(client.GetContent("/index.htm"), "Not Found")
|
||||
t.Assert(client.GetContent("/index.html"), "index")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent("/../main.html"), "Not Found")
|
||||
t.Assert(client.GetContent("/..%2Fmain.html"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/index.htm"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/index.html"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/../main.html"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/..%2Fmain.html"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
@ -97,9 +97,9 @@ func Test_Static_Folder_Forbidden(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Forbidden")
|
||||
t.Assert(client.GetContent("/index.html"), "Not Found")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.Assert(client.GetContent(ctx, "/index.html"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -119,10 +119,10 @@ func Test_Static_IndexFolder(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.AssertNE(client.GetContent("/"), "Forbidden")
|
||||
t.AssertNE(gstr.Pos(client.GetContent("/"), `<a href="/test.html"`), -1)
|
||||
t.Assert(client.GetContent("/index.html"), "Not Found")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.AssertNE(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.AssertNE(gstr.Pos(client.GetContent(ctx, "/"), `<a href="/test.html"`), -1)
|
||||
t.Assert(client.GetContent(ctx, "/index.html"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -142,9 +142,9 @@ func Test_Static_IndexFiles1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "index")
|
||||
t.Assert(client.GetContent("/index.html"), "index")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/index.html"), "index")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -164,9 +164,9 @@ func Test_Static_IndexFiles2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "test")
|
||||
t.Assert(client.GetContent("/index.html"), "Not Found")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/index.html"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -188,8 +188,8 @@ func Test_Static_AddSearchPath1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Forbidden")
|
||||
t.Assert(client.GetContent("/test.html"), "test")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test")
|
||||
})
|
||||
}
|
||||
|
||||
@ -212,8 +212,8 @@ func Test_Static_AddSearchPath2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Forbidden")
|
||||
t.Assert(client.GetContent("/test.html"), "test1")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test1")
|
||||
})
|
||||
}
|
||||
|
||||
@ -236,9 +236,9 @@ func Test_Static_AddStaticPath(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Forbidden")
|
||||
t.Assert(client.GetContent("/test.html"), "test1")
|
||||
t.Assert(client.GetContent("/my-test/test.html"), "test2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test1")
|
||||
t.Assert(client.GetContent(ctx, "/my-test/test.html"), "test2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -261,9 +261,9 @@ func Test_Static_AddStaticPath_Priority(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Forbidden")
|
||||
t.Assert(client.GetContent("/test.html"), "test1")
|
||||
t.Assert(client.GetContent("/test/test.html"), "test2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test1")
|
||||
t.Assert(client.GetContent(ctx, "/test/test.html"), "test2")
|
||||
})
|
||||
}
|
||||
|
||||
@ -288,11 +288,11 @@ func Test_Static_Rewrite(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Forbidden")
|
||||
t.Assert(client.GetContent("/test.html"), "test1")
|
||||
t.Assert(client.GetContent("/test1.html"), "test1")
|
||||
t.Assert(client.GetContent("/test2.html"), "test2")
|
||||
t.Assert(client.GetContent("/my-test1"), "test1")
|
||||
t.Assert(client.GetContent("/my-test2"), "test2")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
|
||||
t.Assert(client.GetContent(ctx, "/test.html"), "test1")
|
||||
t.Assert(client.GetContent(ctx, "/test1.html"), "test1")
|
||||
t.Assert(client.GetContent(ctx, "/test2.html"), "test2")
|
||||
t.Assert(client.GetContent(ctx, "/my-test1"), "test1")
|
||||
t.Assert(client.GetContent(ctx, "/my-test2"), "test2")
|
||||
})
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ func Test_StatusHandler(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/404"), "404")
|
||||
t.Assert(client.GetContent("/502"), "502")
|
||||
t.Assert(client.GetContent(ctx, "/404"), "404")
|
||||
t.Assert(client.GetContent(ctx, "/502"), "502")
|
||||
})
|
||||
}
|
||||
|
||||
@ -63,6 +63,6 @@ func Test_StatusHandler_Multi(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/502"), "12")
|
||||
t.Assert(client.GetContent(ctx, "/502"), "12")
|
||||
})
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ func Test_Template_Basic(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Name:john")
|
||||
t.Assert(client.GetContent("/"), "Name:john")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Name:john")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Name:john")
|
||||
})
|
||||
}
|
||||
|
||||
@ -67,8 +67,8 @@ func Test_Template_Encode(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Name:john")
|
||||
t.Assert(client.GetContent("/"), "Name:john")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Name:john")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Name:john")
|
||||
})
|
||||
}
|
||||
|
||||
@ -96,9 +96,9 @@ func Test_Template_Layout1(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/layout"), "123")
|
||||
t.Assert(client.GetContent("/nil"), "123")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/layout"), "123")
|
||||
t.Assert(client.GetContent(ctx, "/nil"), "123")
|
||||
})
|
||||
}
|
||||
|
||||
@ -132,10 +132,10 @@ func Test_Template_Layout2(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), "Not Found")
|
||||
t.Assert(client.GetContent("/main1"), "a1b")
|
||||
t.Assert(client.GetContent("/main2"), "a2b")
|
||||
t.Assert(client.GetContent("/nil"), "ab")
|
||||
t.Assert(client.GetContent(ctx, "/"), "Not Found")
|
||||
t.Assert(client.GetContent(ctx, "/main1"), "a1b")
|
||||
t.Assert(client.GetContent(ctx, "/main2"), "a2b")
|
||||
t.Assert(client.GetContent(ctx, "/nil"), "ab")
|
||||
})
|
||||
}
|
||||
|
||||
@ -155,8 +155,8 @@ func Test_Template_BuildInVarRequest(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/user/test"), "user")
|
||||
t.Assert(client.GetContent("/order/test"), "order")
|
||||
t.Assert(client.GetContent(ctx, "/user/test"), "user")
|
||||
t.Assert(client.GetContent(ctx, "/order/test"), "order")
|
||||
})
|
||||
}
|
||||
|
||||
@ -182,6 +182,6 @@ func Test_Template_XSS(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/"), ghtml.Entities(c))
|
||||
t.Assert(client.GetContent(ctx, "/"), ghtml.Entities(c))
|
||||
})
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func ExampleClient_Header() {
|
||||
"Trace-Id": "123456789",
|
||||
}
|
||||
)
|
||||
content := g.Client().Header(header).PostContent(url, g.Map{
|
||||
content := g.Client().Header(header).PostContent(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})
|
||||
@ -39,7 +39,7 @@ Span-Id: 0.1
|
||||
Trace-Id: 123456789
|
||||
`
|
||||
)
|
||||
content := g.Client().HeaderRaw(headerRaw).PostContent(url, g.Map{
|
||||
content := g.Client().HeaderRaw(headerRaw).PostContent(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})
|
||||
@ -56,7 +56,7 @@ func ExampleClient_Cookie() {
|
||||
"SessionId": "123",
|
||||
}
|
||||
)
|
||||
content := g.Client().Cookie(cookie).PostContent(url, g.Map{
|
||||
content := g.Client().Cookie(cookie).PostContent(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})
|
||||
@ -76,9 +76,9 @@ func ExampleClient_ContentJson() {
|
||||
}
|
||||
)
|
||||
// Post using JSON string.
|
||||
fmt.Println(g.Client().ContentJson().PostContent(url, jsonStr))
|
||||
fmt.Println(g.Client().ContentJson().PostContent(ctx, url, jsonStr))
|
||||
// Post using JSON map.
|
||||
fmt.Println(g.Client().ContentJson().PostContent(url, jsonMap))
|
||||
fmt.Println(g.Client().ContentJson().PostContent(ctx, url, jsonMap))
|
||||
|
||||
// Output:
|
||||
// Content-Type: application/json, id: 10000
|
||||
|
@ -7,15 +7,20 @@
|
||||
package ghttp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
)
|
||||
|
||||
func ExampleClient_Get() {
|
||||
url := "http://127.0.0.1:8999"
|
||||
var (
|
||||
ctx = context.Background()
|
||||
url = "http://127.0.0.1:8999"
|
||||
)
|
||||
|
||||
// Send with string parameter along with URL.
|
||||
r1, err := g.Client().Get(url + "?id=10000&name=john")
|
||||
r1, err := g.Client().Get(ctx, url+"?id=10000&name=john")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -23,7 +28,7 @@ func ExampleClient_Get() {
|
||||
fmt.Println(r1.ReadAllString())
|
||||
|
||||
// Send with string parameter in request body.
|
||||
r2, err := g.Client().Get(url, "id=10000&name=john")
|
||||
r2, err := g.Client().Get(ctx, url, "id=10000&name=john")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -31,7 +36,7 @@ func ExampleClient_Get() {
|
||||
fmt.Println(r2.ReadAllString())
|
||||
|
||||
// Send with map parameter.
|
||||
r3, err := g.Client().Get(url, g.Map{
|
||||
r3, err := g.Client().Get(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})
|
||||
@ -48,8 +53,11 @@ func ExampleClient_Get() {
|
||||
}
|
||||
|
||||
func ExampleClient_GetBytes() {
|
||||
url := "http://127.0.0.1:8999"
|
||||
fmt.Println(string(g.Client().GetBytes(url, g.Map{
|
||||
var (
|
||||
ctx = context.Background()
|
||||
url = "http://127.0.0.1:8999"
|
||||
)
|
||||
fmt.Println(string(g.Client().GetBytes(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})))
|
||||
@ -60,7 +68,7 @@ func ExampleClient_GetBytes() {
|
||||
|
||||
func ExampleClient_GetContent() {
|
||||
url := "http://127.0.0.1:8999"
|
||||
fmt.Println(g.Client().GetContent(url, g.Map{
|
||||
fmt.Println(g.Client().GetContent(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
}))
|
||||
@ -76,9 +84,10 @@ func ExampleClient_GetVar() {
|
||||
}
|
||||
var (
|
||||
user *User
|
||||
ctx = context.Background()
|
||||
url = "http://127.0.0.1:8999/var/json"
|
||||
)
|
||||
err := g.Client().GetVar(url).Scan(&user)
|
||||
err := g.Client().GetVar(ctx, url).Scan(&user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
func ExampleClient_Post() {
|
||||
url := "http://127.0.0.1:8999"
|
||||
// Send with string parameter in request body.
|
||||
r1, err := g.Client().Post(url, "id=10000&name=john")
|
||||
r1, err := g.Client().Post(ctx, url, "id=10000&name=john")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -22,7 +22,7 @@ func ExampleClient_Post() {
|
||||
fmt.Println(r1.ReadAllString())
|
||||
|
||||
// Send with map parameter.
|
||||
r2, err := g.Client().Post(url, g.Map{
|
||||
r2, err := g.Client().Post(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})
|
||||
@ -39,7 +39,7 @@ func ExampleClient_Post() {
|
||||
|
||||
func ExampleClient_PostBytes() {
|
||||
url := "http://127.0.0.1:8999"
|
||||
fmt.Println(string(g.Client().PostBytes(url, g.Map{
|
||||
fmt.Println(string(g.Client().PostBytes(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
})))
|
||||
@ -50,7 +50,7 @@ func ExampleClient_PostBytes() {
|
||||
|
||||
func ExampleClient_PostContent() {
|
||||
url := "http://127.0.0.1:8999"
|
||||
fmt.Println(g.Client().PostContent(url, g.Map{
|
||||
fmt.Println(g.Client().PostContent(ctx, url, g.Map{
|
||||
"id": 10000,
|
||||
"name": "john",
|
||||
}))
|
||||
@ -68,7 +68,7 @@ func ExampleClient_PostVar() {
|
||||
users []User
|
||||
url = "http://127.0.0.1:8999/var/jsons"
|
||||
)
|
||||
err := g.Client().PostVar(url).Scan(&users)
|
||||
err := g.Client().PostVar(ctx, url).Scan(&users)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
package ghttp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
@ -45,7 +46,10 @@ func ExampleUploadFile_Save() {
|
||||
}
|
||||
|
||||
func ExampleClientResponse_RawDump() {
|
||||
response, err := g.Client().Get("https://goframe.org")
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
response, err := g.Client().Get(ctx, "https://goframe.org")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -61,7 +65,7 @@ func ExampleClient_SetProxy() {
|
||||
client := g.Client()
|
||||
client.SetProxy("http://127.0.0.1:1081")
|
||||
client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout
|
||||
response, err := client.Get("https://api.ip.sb/ip")
|
||||
response, err := client.Get(ctx, "https://api.ip.sb/ip")
|
||||
if err != nil {
|
||||
// err is not nil when your proxy server is down.
|
||||
// eg. Get "https://api.ip.sb/ip": proxyconnect tcp: dial tcp 127.0.0.1:1087: connect: connection refused
|
||||
@ -71,7 +75,7 @@ func ExampleClient_SetProxy() {
|
||||
// connect to a http proxy server which needs auth
|
||||
client.SetProxy("http://user:password:127.0.0.1:1081")
|
||||
client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout
|
||||
response, err = client.Get("https://api.ip.sb/ip")
|
||||
response, err = client.Get(ctx, "https://api.ip.sb/ip")
|
||||
if err != nil {
|
||||
// err is not nil when your proxy server is down.
|
||||
// eg. Get "https://api.ip.sb/ip": proxyconnect tcp: dial tcp 127.0.0.1:1087: connect: connection refused
|
||||
@ -82,7 +86,7 @@ func ExampleClient_SetProxy() {
|
||||
// connect to a socks5 proxy server
|
||||
client.SetProxy("socks5://127.0.0.1:1080")
|
||||
client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout
|
||||
response, err = client.Get("https://api.ip.sb/ip")
|
||||
response, err = client.Get(ctx, "https://api.ip.sb/ip")
|
||||
if err != nil {
|
||||
// err is not nil when your proxy server is down.
|
||||
// eg. Get "https://api.ip.sb/ip": socks connect tcp 127.0.0.1:1087->api.ip.sb:443: dial tcp 127.0.0.1:1087: connect: connection refused
|
||||
@ -93,7 +97,7 @@ func ExampleClient_SetProxy() {
|
||||
// connect to a socks5 proxy server which needs auth
|
||||
client.SetProxy("socks5://user:password@127.0.0.1:1080")
|
||||
client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout
|
||||
response, err = client.Get("https://api.ip.sb/ip")
|
||||
response, err = client.Get(ctx, "https://api.ip.sb/ip")
|
||||
if err != nil {
|
||||
// err is not nil when your proxy server is down.
|
||||
// eg. Get "https://api.ip.sb/ip": socks connect tcp 127.0.0.1:1087->api.ip.sb:443: dial tcp 127.0.0.1:1087: connect: connection refused
|
||||
@ -108,8 +112,11 @@ func ExampleClient_SetProxy() {
|
||||
// socks5 proxy server listening on `127.0.0.1:1080`
|
||||
// for more details, please refer to ExampleClient_SetProxy
|
||||
func ExampleClientChain_Proxy() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
client := g.Client()
|
||||
response, err := client.Proxy("http://127.0.0.1:1081").Get("https://api.ip.sb/ip")
|
||||
response, err := client.Proxy("http://127.0.0.1:1081").Get(ctx, "https://api.ip.sb/ip")
|
||||
if err != nil {
|
||||
// err is not nil when your proxy server is down.
|
||||
// eg. Get "https://api.ip.sb/ip": proxyconnect tcp: dial tcp 127.0.0.1:1087: connect: connection refused
|
||||
@ -118,7 +125,7 @@ func ExampleClientChain_Proxy() {
|
||||
fmt.Println(response.RawResponse())
|
||||
|
||||
client2 := g.Client()
|
||||
response, err = client2.Proxy("socks5://127.0.0.1:1080").Get("https://api.ip.sb/ip")
|
||||
response, err = client2.Proxy("socks5://127.0.0.1:1080").Get(ctx, "https://api.ip.sb/ip")
|
||||
if err != nil {
|
||||
// err is not nil when your proxy server is down.
|
||||
// eg. Get "https://api.ip.sb/ip": socks connect tcp 127.0.0.1:1087->api.ip.sb:443: dial tcp 127.0.0.1:1087: connect: connection refused
|
||||
|
@ -30,7 +30,6 @@ import (
|
||||
// Client is the HTTP client for HTTP request management.
|
||||
type Client struct {
|
||||
http.Client // Underlying HTTP Client.
|
||||
ctx context.Context // Context for each request.
|
||||
dump bool // Mark this request will be dumped.
|
||||
parent *Client // Parent http client, this is used for chaining operations.
|
||||
header map[string]string // Custom header map.
|
||||
@ -168,12 +167,6 @@ func (c *Client) SetBasicAuth(user, pass string) *Client {
|
||||
return c
|
||||
}
|
||||
|
||||
// SetCtx sets context for each request of this client.
|
||||
func (c *Client) SetCtx(ctx context.Context) *Client {
|
||||
c.ctx = ctx
|
||||
return c
|
||||
}
|
||||
|
||||
// SetRetry sets retry count and interval.
|
||||
func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client {
|
||||
c.retryCount = retryCount
|
||||
|
@ -6,58 +6,67 @@
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/internal/intlog"
|
||||
)
|
||||
|
||||
// GetBytes sends a GET request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) GetBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("GET", url, data...)
|
||||
func (c *Client) GetBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "GET", url, data...)
|
||||
}
|
||||
|
||||
// PutBytes sends a PUT request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) PutBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("PUT", url, data...)
|
||||
func (c *Client) PutBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "PUT", url, data...)
|
||||
}
|
||||
|
||||
// PostBytes sends a POST request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) PostBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("POST", url, data...)
|
||||
func (c *Client) PostBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "POST", url, data...)
|
||||
}
|
||||
|
||||
// DeleteBytes sends a DELETE request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) DeleteBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("DELETE", url, data...)
|
||||
func (c *Client) DeleteBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "DELETE", url, data...)
|
||||
}
|
||||
|
||||
// HeadBytes sends a HEAD request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) HeadBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("HEAD", url, data...)
|
||||
func (c *Client) HeadBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "HEAD", url, data...)
|
||||
}
|
||||
|
||||
// PatchBytes sends a PATCH request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) PatchBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("PATCH", url, data...)
|
||||
func (c *Client) PatchBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "PATCH", url, data...)
|
||||
}
|
||||
|
||||
// ConnectBytes sends a CONNECT request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) ConnectBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("CONNECT", url, data...)
|
||||
func (c *Client) ConnectBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "CONNECT", url, data...)
|
||||
}
|
||||
|
||||
// OptionsBytes sends a OPTIONS request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) OptionsBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("OPTIONS", url, data...)
|
||||
func (c *Client) OptionsBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "OPTIONS", url, data...)
|
||||
}
|
||||
|
||||
// TraceBytes sends a TRACE request, retrieves and returns the result content as bytes.
|
||||
func (c *Client) TraceBytes(url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes("TRACE", url, data...)
|
||||
func (c *Client) TraceBytes(ctx context.Context, url string, data ...interface{}) []byte {
|
||||
return c.RequestBytes(ctx, "TRACE", url, data...)
|
||||
}
|
||||
|
||||
// RequestBytes sends request using given HTTP method and data, retrieves returns the result
|
||||
// as bytes. It reads and closes the response object internally automatically.
|
||||
func (c *Client) RequestBytes(method string, url string, data ...interface{}) []byte {
|
||||
response, err := c.DoRequest(method, url, data...)
|
||||
func (c *Client) RequestBytes(ctx context.Context, method string, url string, data ...interface{}) []byte {
|
||||
response, err := c.DoRequest(ctx, method, url, data...)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer response.Close()
|
||||
defer func() {
|
||||
if err := response.Close(); err != nil {
|
||||
intlog.Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
return response.ReadAll()
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -114,17 +113,6 @@ func (c *Client) BasicAuth(user, pass string) *Client {
|
||||
return newClient
|
||||
}
|
||||
|
||||
// Ctx is a chaining function,
|
||||
// which sets context for next request of this client.
|
||||
func (c *Client) Ctx(ctx context.Context) *Client {
|
||||
newClient := c
|
||||
if c.parent == nil {
|
||||
newClient = c.Clone()
|
||||
}
|
||||
newClient.SetCtx(ctx)
|
||||
return newClient
|
||||
}
|
||||
|
||||
// Retry is a chaining function,
|
||||
// which sets retry count and interval when failure for next request.
|
||||
func (c *Client) Retry(retryCount int, retryInterval time.Duration) *Client {
|
||||
|
@ -6,62 +6,64 @@
|
||||
|
||||
package client
|
||||
|
||||
import "context"
|
||||
|
||||
// GetContent is a convenience method for sending GET request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) GetContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("GET", url, data...))
|
||||
func (c *Client) GetContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "GET", url, data...))
|
||||
}
|
||||
|
||||
// PutContent is a convenience method for sending PUT request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) PutContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("PUT", url, data...))
|
||||
func (c *Client) PutContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "PUT", url, data...))
|
||||
}
|
||||
|
||||
// PostContent is a convenience method for sending POST request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) PostContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("POST", url, data...))
|
||||
func (c *Client) PostContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "POST", url, data...))
|
||||
}
|
||||
|
||||
// DeleteContent is a convenience method for sending DELETE request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) DeleteContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("DELETE", url, data...))
|
||||
func (c *Client) DeleteContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "DELETE", url, data...))
|
||||
}
|
||||
|
||||
// HeadContent is a convenience method for sending HEAD request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) HeadContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("HEAD", url, data...))
|
||||
func (c *Client) HeadContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "HEAD", url, data...))
|
||||
}
|
||||
|
||||
// PatchContent is a convenience method for sending PATCH request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) PatchContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("PATCH", url, data...))
|
||||
func (c *Client) PatchContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "PATCH", url, data...))
|
||||
}
|
||||
|
||||
// ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) ConnectContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("CONNECT", url, data...))
|
||||
func (c *Client) ConnectContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "CONNECT", url, data...))
|
||||
}
|
||||
|
||||
// OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) OptionsContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("OPTIONS", url, data...))
|
||||
func (c *Client) OptionsContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "OPTIONS", url, data...))
|
||||
}
|
||||
|
||||
// TraceContent is a convenience method for sending TRACE request, which retrieves and returns
|
||||
// the result content and automatically closes response object.
|
||||
func (c *Client) TraceContent(url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes("TRACE", url, data...))
|
||||
func (c *Client) TraceContent(ctx context.Context, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, "TRACE", url, data...))
|
||||
}
|
||||
|
||||
// RequestContent is a convenience method for sending custom http method request, which
|
||||
// retrieves and returns the result content and automatically closes response object.
|
||||
func (c *Client) RequestContent(method string, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(method, url, data...))
|
||||
func (c *Client) RequestContent(ctx context.Context, method string, url string, data ...interface{}) string {
|
||||
return string(c.RequestBytes(ctx, method, url, data...))
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ func (c *Client) Use(handlers ...HandlerFunc) *Client {
|
||||
return c
|
||||
}
|
||||
|
||||
// Next calls next middleware.
|
||||
// This is should only be call in HandlerFunc.
|
||||
// Next calls the next middleware.
|
||||
// This should only be call in HandlerFunc.
|
||||
func (c *Client) Next(req *http.Request) (*Response, error) {
|
||||
if v := req.Context().Value(clientMiddlewareKey); v != nil {
|
||||
if m, ok := v.(*clientMiddleware); ok {
|
||||
@ -35,7 +35,7 @@ func (c *Client) Next(req *http.Request) (*Response, error) {
|
||||
return c.callRequest(req)
|
||||
}
|
||||
|
||||
// Next calls next middleware handler.
|
||||
// Next calls the next middleware handler.
|
||||
func (m *clientMiddleware) Next(req *http.Request) (resp *Response, err error) {
|
||||
if m.err != nil {
|
||||
return m.resp, m.err
|
||||
|
@ -32,68 +32,68 @@ import (
|
||||
)
|
||||
|
||||
// Get send GET request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Get(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("GET", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Get(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "GET", url, data...)
|
||||
}
|
||||
|
||||
// Put send PUT request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Put(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("PUT", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Put(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "PUT", url, data...)
|
||||
}
|
||||
|
||||
// Post sends request using HTTP method POST and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Post(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("POST", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Post(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "POST", url, data...)
|
||||
}
|
||||
|
||||
// Delete send DELETE request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Delete(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("DELETE", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Delete(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "DELETE", url, data...)
|
||||
}
|
||||
|
||||
// Head send HEAD request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Head(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("HEAD", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Head(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "HEAD", url, data...)
|
||||
}
|
||||
|
||||
// Patch send PATCH request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Patch(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("PATCH", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Patch(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "PATCH", url, data...)
|
||||
}
|
||||
|
||||
// Connect send CONNECT request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Connect(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("CONNECT", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Connect(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "CONNECT", url, data...)
|
||||
}
|
||||
|
||||
// Options send OPTIONS request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Options(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("OPTIONS", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Options(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "OPTIONS", url, data...)
|
||||
}
|
||||
|
||||
// Trace send TRACE request and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
func (c *Client) Trace(url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest("TRACE", url, data...)
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) Trace(ctx context.Context, url string, data ...interface{}) (*Response, error) {
|
||||
return c.DoRequest(ctx, "TRACE", url, data...)
|
||||
}
|
||||
|
||||
// DoRequest sends request with given HTTP method and data and returns the response object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
//
|
||||
// Note that it uses "multipart/form-data" as its Content-Type if it contains file uploading,
|
||||
// else it uses "application/x-www-form-urlencoded". It also automatically detects the post
|
||||
// content for JSON format, and for that it automatically sets the Content-Type as
|
||||
// "application/json".
|
||||
func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Response, err error) {
|
||||
req, err := c.prepareRequest(method, url, data...)
|
||||
func (c *Client) DoRequest(ctx context.Context, method, url string, data ...interface{}) (resp *Response, err error) {
|
||||
req, err := c.prepareRequest(ctx, method, url, data...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -105,7 +105,7 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Respo
|
||||
mdlHandlers = append(mdlHandlers, func(cli *Client, r *http.Request) (*Response, error) {
|
||||
return cli.callRequest(r)
|
||||
})
|
||||
ctx := context.WithValue(req.Context(), clientMiddlewareKey, &clientMiddleware{
|
||||
ctx = context.WithValue(req.Context(), clientMiddlewareKey, &clientMiddleware{
|
||||
client: c,
|
||||
handlers: mdlHandlers,
|
||||
handlerIndex: -1,
|
||||
@ -119,7 +119,7 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Respo
|
||||
}
|
||||
|
||||
// prepareRequest verifies request parameters, builds and returns http request.
|
||||
func (c *Client) prepareRequest(method, url string, data ...interface{}) (req *http.Request, err error) {
|
||||
func (c *Client) prepareRequest(ctx context.Context, method, url string, data ...interface{}) (req *http.Request, err error) {
|
||||
method = strings.ToUpper(method)
|
||||
if len(c.prefix) > 0 {
|
||||
url = c.prefix + gstr.Trim(url)
|
||||
@ -196,12 +196,12 @@ func (c *Client) prepareRequest(method, url string, data ...interface{}) (req *h
|
||||
if f, err := os.Open(path); err == nil {
|
||||
if _, err = io.Copy(file, f); err != nil {
|
||||
if err := f.Close(); err != nil {
|
||||
intlog.Errorf(c.ctx, `%+v`, err)
|
||||
intlog.Errorf(ctx, `%+v`, err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
intlog.Errorf(c.ctx, `%+v`, err)
|
||||
intlog.Errorf(ctx, `%+v`, err)
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
@ -249,10 +249,8 @@ func (c *Client) prepareRequest(method, url string, data ...interface{}) (req *h
|
||||
}
|
||||
|
||||
// Context.
|
||||
if c.ctx != nil {
|
||||
req = req.WithContext(c.ctx)
|
||||
} else {
|
||||
req = req.WithContext(context.Background())
|
||||
if ctx != nil {
|
||||
req = req.WithContext(ctx)
|
||||
}
|
||||
// Custom header.
|
||||
if len(c.header) > 0 {
|
||||
@ -286,8 +284,9 @@ func (c *Client) prepareRequest(method, url string, data ...interface{}) (req *h
|
||||
}
|
||||
|
||||
// callRequest sends request with give http.Request, and returns the responses object.
|
||||
// Note that the response object MUST be closed if it'll be never used.
|
||||
// Note that the response object MUST be closed if it'll never be used.
|
||||
func (c *Client) callRequest(req *http.Request) (resp *Response, err error) {
|
||||
ctx := req.Context()
|
||||
resp = &Response{
|
||||
request: req,
|
||||
}
|
||||
@ -304,7 +303,7 @@ func (c *Client) callRequest(req *http.Request) (resp *Response, err error) {
|
||||
// The response might not be nil when err != nil.
|
||||
if resp.Response != nil {
|
||||
if err := resp.Response.Body.Close(); err != nil {
|
||||
intlog.Errorf(c.ctx, `%+v`, err)
|
||||
intlog.Errorf(ctx, `%+v`, err)
|
||||
}
|
||||
}
|
||||
if c.retryCount > 0 {
|
||||
|
@ -7,68 +7,69 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
)
|
||||
|
||||
// GetVar sends a GET request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) GetVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("GET", url, data...)
|
||||
func (c *Client) GetVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "GET", url, data...)
|
||||
}
|
||||
|
||||
// PutVar sends a PUT request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) PutVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("PUT", url, data...)
|
||||
func (c *Client) PutVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "PUT", url, data...)
|
||||
}
|
||||
|
||||
// PostVar sends a POST request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) PostVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("POST", url, data...)
|
||||
func (c *Client) PostVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "POST", url, data...)
|
||||
}
|
||||
|
||||
// DeleteVar sends a DELETE request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) DeleteVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("DELETE", url, data...)
|
||||
func (c *Client) DeleteVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "DELETE", url, data...)
|
||||
}
|
||||
|
||||
// HeadVar sends a HEAD request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) HeadVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("HEAD", url, data...)
|
||||
func (c *Client) HeadVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "HEAD", url, data...)
|
||||
}
|
||||
|
||||
// PatchVar sends a PATCH request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) PatchVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("PATCH", url, data...)
|
||||
func (c *Client) PatchVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "PATCH", url, data...)
|
||||
}
|
||||
|
||||
// ConnectVar sends a CONNECT request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) ConnectVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("CONNECT", url, data...)
|
||||
func (c *Client) ConnectVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "CONNECT", url, data...)
|
||||
}
|
||||
|
||||
// OptionsVar sends a OPTIONS request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) OptionsVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("OPTIONS", url, data...)
|
||||
func (c *Client) OptionsVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "OPTIONS", url, data...)
|
||||
}
|
||||
|
||||
// TraceVar sends a TRACE request, retrieves and converts the result content to specified pointer.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) TraceVar(url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar("TRACE", url, data...)
|
||||
func (c *Client) TraceVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
|
||||
return c.RequestVar(ctx, "TRACE", url, data...)
|
||||
}
|
||||
|
||||
// RequestVar sends request using given HTTP method and data, retrieves converts the result
|
||||
// to specified pointer. It reads and closes the response object internally automatically.
|
||||
// The parameter <pointer> can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
|
||||
func (c *Client) RequestVar(method string, url string, data ...interface{}) *gvar.Var {
|
||||
response, err := c.DoRequest(method, url, data...)
|
||||
func (c *Client) RequestVar(ctx context.Context, method string, url string, data ...interface{}) *gvar.Var {
|
||||
response, err := c.DoRequest(ctx, method, url, data...)
|
||||
if err != nil {
|
||||
return gvar.New(nil)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user