complete test for combo case
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
23113d8c9f
commit
fe6ee6b4ac
@ -3,6 +3,8 @@ package combo_test
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -145,14 +147,11 @@ func TestComboServer(t *testing.T) {
|
||||
mgrpcsvc := mgpb.NewTestClient("helloworld", mgcli)
|
||||
|
||||
t.Logf("call via micro grpc")
|
||||
rsp, err := mgrpcsvc.Call(ctx, &pb.CallReq{Req: "my_name"})
|
||||
if err != nil {
|
||||
if rsp, err := mgrpcsvc.Call(ctx, &pb.CallReq{Req: "my_name"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if rsp.Rsp != "name_my_name" {
|
||||
} else if rsp.Rsp != "name_my_name" {
|
||||
t.Fatalf("invalid response: %#+v\n", rsp)
|
||||
}
|
||||
}
|
||||
|
||||
ngcli, err := grpc.DialContext(ctx, service[0].Nodes[0].Address, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
@ -164,20 +163,47 @@ func TestComboServer(t *testing.T) {
|
||||
t.Logf("call via native grpc")
|
||||
if rsp, err := ngrpcsvc.Call(ctx, &ngpb.CallReq{Req: "my_name"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if rsp.Rsp != "name_my_name" {
|
||||
} else if rsp.Rsp != "name_my_name" {
|
||||
t.Fatalf("invalid response: %#+v\n", rsp)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("call via micro http")
|
||||
if rsp, err := mhttpsvc.Call(ctx, &pb.CallReq{Req: "my_name"}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if rsp.Rsp != "name_my_name" {
|
||||
} else if rsp.Rsp != "name_my_name" {
|
||||
t.Fatalf("invalid response: %#+v\n", rsp)
|
||||
}
|
||||
|
||||
var hreq *http.Request
|
||||
hreq, err = http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("http://%s/swagger-ui/index.html", service[0].Nodes[0].Address), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var hrsp *http.Response
|
||||
hrsp, err = http.DefaultClient.Do(hreq)
|
||||
if err != nil || hrsp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("error rsp: %v err: %v", hrsp, err)
|
||||
}
|
||||
|
||||
select {}
|
||||
hreq, err = http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("http://%s/Call", service[0].Nodes[0].Address), strings.NewReader(`{"req":"my_name"}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hreq.Header.Add("Content-Type", "application/json")
|
||||
|
||||
hrsp, err = http.DefaultClient.Do(hreq)
|
||||
if err != nil || hrsp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("error rsp: %v err: %v", hrsp, err)
|
||||
}
|
||||
defer hrsp.Body.Close()
|
||||
buf, err := io.ReadAll(hrsp.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("read body fail: %v", err)
|
||||
}
|
||||
rsp := &pb.CallRsp{}
|
||||
if err = jsonpbcodec.NewCodec().Unmarshal(buf, rsp); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if rsp.Rsp != "name_my_name" {
|
||||
t.Fatalf("invalid response: %#+v\n", rsp)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user