add more http client tests
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
a308d65b9c
commit
e7dc3c5fb3
@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@ -35,6 +36,31 @@ type GithubRsp struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type GithubRspError struct {
|
||||
Message string `json:"message"`
|
||||
DocumentationUrl string `json:"documentation_url"`
|
||||
}
|
||||
|
||||
func (e *GithubRspError) Error() string {
|
||||
b, _ := json.Marshal(e)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TestNativeError(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", "/dddd", nil)
|
||||
rsp := &GithubRsp{}
|
||||
errMap := map[string]interface{}{"404": &GithubRspError{}}
|
||||
err := c.Call(context.TODO(), req, rsp, mhttp.Method(http.MethodGet), mhttp.ErrorMap(errMap))
|
||||
if err == nil {
|
||||
t.Fatal("request must return non nil err")
|
||||
}
|
||||
if _, ok := err.(*GithubRspError); !ok {
|
||||
t.Fatalf("invalid response received: %T is not *GithubRspError type", err)
|
||||
}
|
||||
t.Logf("reponse: %s", err.Error())
|
||||
}
|
||||
|
||||
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)
|
||||
|
3
go.mod
3
go.mod
@ -12,7 +12,7 @@ require (
|
||||
github.com/unistack-org/micro-broker-http v0.0.0-20201125231853-bb4bd204b8c0
|
||||
github.com/unistack-org/micro-broker-memory v0.0.2-0.20201105185131-5ff932308afd
|
||||
github.com/unistack-org/micro-client-grpc v0.0.2-0.20201228123319-bbd07bb0914a
|
||||
github.com/unistack-org/micro-client-http v0.0.0-20201222205226-c4f2d68e4e3e
|
||||
github.com/unistack-org/micro-client-http v0.0.0-20210105043204-d541c7cc54f5
|
||||
github.com/unistack-org/micro-codec-grpc v0.0.0-20201220205513-cad30014cbf2
|
||||
github.com/unistack-org/micro-codec-json v0.0.0-20201220205604-ed33fab21d87
|
||||
github.com/unistack-org/micro-codec-proto v0.0.0-20201220205718-066176ab59b7
|
||||
@ -30,4 +30,5 @@ require (
|
||||
google.golang.org/protobuf v1.25.0
|
||||
)
|
||||
|
||||
//replace github.com/unistack-org/micro-client-http => ../done/micro-client-http
|
||||
//replace github.com/unistack-org/micro/v3 => ../micro
|
||||
|
4
go.sum
4
go.sum
@ -422,8 +422,8 @@ github.com/unistack-org/micro-broker-memory v0.0.2-0.20201105185131-5ff932308afd
|
||||
github.com/unistack-org/micro-broker-memory v0.0.2-0.20201105185131-5ff932308afd/go.mod h1:BlX+zLHGZxNngsiGiAaIqt0XjwIk3iurw4cqRFYRaVk=
|
||||
github.com/unistack-org/micro-client-grpc v0.0.2-0.20201228123319-bbd07bb0914a h1:AgtyOyt52SveHJdk08Z+rodtKPUcLFn+fhNVk/dHTWw=
|
||||
github.com/unistack-org/micro-client-grpc v0.0.2-0.20201228123319-bbd07bb0914a/go.mod h1:+/sN0ylUHLaDODABbxPBx8y7WUY8PUjzMF1L7cmNk4M=
|
||||
github.com/unistack-org/micro-client-http v0.0.0-20201222205226-c4f2d68e4e3e h1:J3nRJP41a+FZcIdwPU4S1qAjy1NT4SH04OlbFKck/jw=
|
||||
github.com/unistack-org/micro-client-http v0.0.0-20201222205226-c4f2d68e4e3e/go.mod h1:vb+5C+r23Q8H5FTpcwGT3XwaenKeGBY7SMcFo+UUV4k=
|
||||
github.com/unistack-org/micro-client-http v0.0.0-20210105043204-d541c7cc54f5 h1:uoL2SK2HiXAReHaemoTLSxmNQvV+bzvP6Ci8V0wsN+8=
|
||||
github.com/unistack-org/micro-client-http v0.0.0-20210105043204-d541c7cc54f5/go.mod h1:vb+5C+r23Q8H5FTpcwGT3XwaenKeGBY7SMcFo+UUV4k=
|
||||
github.com/unistack-org/micro-codec-bytes v0.0.0-20200827104921-3616a69473a6/go.mod h1:g5sOI8TWgGZiVHe8zoUPdtz7+0oLnqTnfBoai6Qb7jE=
|
||||
github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844/go.mod h1:g5sOI8TWgGZiVHe8zoUPdtz7+0oLnqTnfBoai6Qb7jE=
|
||||
github.com/unistack-org/micro-codec-grpc v0.0.0-20201220205513-cad30014cbf2 h1:pfkUfnSi5kSkZkHBcqOKCm/Dv/IcMwMxWlei8T+5ADc=
|
||||
|
Loading…
Reference in New Issue
Block a user