update tests
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
b6530770a1
commit
c335e0f011
2
go.mod
2
go.mod
@ -29,7 +29,7 @@ require (
|
|||||||
github.com/unistack-org/micro-server-http/v3 v3.3.1
|
github.com/unistack-org/micro-server-http/v3 v3.3.1
|
||||||
github.com/unistack-org/micro-server-tcp/v3 v3.3.0
|
github.com/unistack-org/micro-server-tcp/v3 v3.3.0
|
||||||
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0
|
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0
|
||||||
github.com/unistack-org/micro/v3 v3.3.8
|
github.com/unistack-org/micro/v3 v3.3.9
|
||||||
google.golang.org/genproto v0.0.0-20210325224202-eed09b1b5210
|
google.golang.org/genproto v0.0.0-20210325224202-eed09b1b5210
|
||||||
google.golang.org/grpc v1.36.1
|
google.golang.org/grpc v1.36.1
|
||||||
google.golang.org/protobuf v1.26.0
|
google.golang.org/protobuf v1.26.0
|
||||||
|
4
go.sum
4
go.sum
@ -497,8 +497,8 @@ github.com/unistack-org/micro/v3 v3.2.22/go.mod h1:oI8H/uGq1h4i5cvUycEoFKJQC7G8y
|
|||||||
github.com/unistack-org/micro/v3 v3.2.24/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
github.com/unistack-org/micro/v3 v3.2.24/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
||||||
github.com/unistack-org/micro/v3 v3.3.0/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
github.com/unistack-org/micro/v3 v3.3.0/go.mod h1:iJwCWq2PECMxigfqe6TPC5GLWvj6P94Kk+PTVZGL3w8=
|
||||||
github.com/unistack-org/micro/v3 v3.3.3/go.mod h1:tX95c0Qx4w6oqU7qKThs9lya9P507BdZ29MsTVDmU6w=
|
github.com/unistack-org/micro/v3 v3.3.3/go.mod h1:tX95c0Qx4w6oqU7qKThs9lya9P507BdZ29MsTVDmU6w=
|
||||||
github.com/unistack-org/micro/v3 v3.3.8 h1:4e4gWuZI/cRUGZ6ZZpdrIDOF2MLO6cjHxeFfZzy610Y=
|
github.com/unistack-org/micro/v3 v3.3.9 h1:NFF4wymDDxgYeZU++04BxvETrrAnd0iNzVyfm/ssQI4=
|
||||||
github.com/unistack-org/micro/v3 v3.3.8/go.mod h1:M3RGgKZX1OlTn0QB+3R1tlSoGwmEg6rb/Isr0lLYmjQ=
|
github.com/unistack-org/micro/v3 v3.3.9/go.mod h1:M3RGgKZX1OlTn0QB+3R1tlSoGwmEg6rb/Isr0lLYmjQ=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI=
|
github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI=
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package http_test
|
package http_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -33,7 +34,7 @@ type Handler struct {
|
|||||||
func NewServerHandlerWrapper() server.HandlerWrapper {
|
func NewServerHandlerWrapper() server.HandlerWrapper {
|
||||||
return func(fn server.HandlerFunc) server.HandlerFunc {
|
return func(fn server.HandlerFunc) server.HandlerFunc {
|
||||||
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
return func(ctx context.Context, req server.Request, rsp interface{}) error {
|
||||||
fmt.Printf("wrap ctx: %#+v req: %#+v\n", ctx, req)
|
fmt.Printf("wrap ctx: %s\n", req.Service())
|
||||||
return fn(ctx, req, rsp)
|
return fn(ctx, req, rsp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +114,7 @@ func TestNativeClientServer(t *testing.T) {
|
|||||||
if err := pb.RegisterTestDoubleServer(srv, h); err != nil {
|
if err := pb.RegisterTestDoubleServer(srv, h); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := handler.RegisterMeterServer(srv, handler.NewHandler(srv.Options().Meter)); err != nil {
|
if err := handler.RegisterMeterServer(srv, handler.NewHandler(handler.Meter(srv.Options().Meter))); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// start server
|
// start server
|
||||||
@ -158,6 +159,38 @@ func TestNativeClientServer(t *testing.T) {
|
|||||||
t.Fatalf("http middleware not works")
|
t.Fatalf("http middleware not works")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hb, err := jsonpbcodec.NewCodec().Marshal(&pb.CallReq{
|
||||||
|
Nested: &pb.Nested{Uint64Args: []*wrapperspb.UInt64Value{
|
||||||
|
&wrapperspb.UInt64Value{Value: 1},
|
||||||
|
&wrapperspb.UInt64Value{Value: 2},
|
||||||
|
&wrapperspb.UInt64Value{Value: 3},
|
||||||
|
}},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("test rsp code from net/http client to native micro http server")
|
||||||
|
hr, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("http://%s/v1/test/call/my_name", service[0].Nodes[0].Address), bytes.NewReader(hb))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
hr.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
hrsp, err := http.DefaultClient.Do(hr)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer hrsp.Body.Close()
|
||||||
|
buf, err := io.ReadAll(hrsp.Body)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hrsp.StatusCode != 201 {
|
||||||
|
t.Fatalf("invalid rsp code %#+v", hrsp)
|
||||||
|
}
|
||||||
|
|
||||||
t.Logf("test second server")
|
t.Logf("test second server")
|
||||||
svc2 := pb.NewTestDoubleClient("helloworld", cli)
|
svc2 := pb.NewTestDoubleClient("helloworld", cli)
|
||||||
rsp, err = svc2.CallDouble(ctx, &pb.CallReq{
|
rsp, err = svc2.CallDouble(ctx, &pb.CallReq{
|
||||||
@ -171,12 +204,12 @@ func TestNativeClientServer(t *testing.T) {
|
|||||||
t.Fatalf("invalid response: %#+v\n", rsp)
|
t.Fatalf("invalid response: %#+v\n", rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
hr, err := http.Get(fmt.Sprintf("http://%s/metrics", service[0].Nodes[0].Address))
|
hrsp, err = http.Get(fmt.Sprintf("http://%s/metrics", service[0].Nodes[0].Address))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := io.ReadAll(hr.Body)
|
buf, err = io.ReadAll(hrsp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user