add native http test case

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-12-16 00:00:31 +03:00
parent d2e120478f
commit 0b3005f71e

View File

@ -31,6 +31,24 @@ type Message struct {
Data string
}
type GithubRsp struct {
Name string `json:"name,omitempty"`
}
func TestNative(t *testing.T) {
c := client.NewClientCallOptions(mhttp.NewClient(client.ContentType("application/json"), client.Codec("application/json", jsoncodec.NewCodec())), client.WithAddress("https://api.github.com"))
req := c.NewRequest("github", "/users/vtolstov", nil)
rsp := &GithubRsp{}
err := c.Call(context.TODO(), req, rsp, mhttp.Method(http.MethodGet))
if err != nil {
t.Fatal(err)
}
if rsp.Name != "Vasiliy Tolstov" {
t.Fatalf("invlid rsp received: %#+v\n", rsp)
}
}
func TestHTTPClient(t *testing.T) {
reg := rmemory.NewRegistry()
rtr := rrouter.NewRouter(router.Registry(reg))