add tests for http middlewares

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-07 13:31:39 +03:00
parent 025b34cb21
commit d1590d274b
3 changed files with 16 additions and 3 deletions

2
go.mod
View File

@ -28,7 +28,7 @@ require (
github.com/unistack-org/micro-register-memory/v3 v3.2.2 github.com/unistack-org/micro-register-memory/v3 v3.2.2
github.com/unistack-org/micro-router-register/v3 v3.2.2 github.com/unistack-org/micro-router-register/v3 v3.2.2
github.com/unistack-org/micro-server-grpc/v3 v3.2.2 github.com/unistack-org/micro-server-grpc/v3 v3.2.2
github.com/unistack-org/micro-server-http/v3 v3.2.3 github.com/unistack-org/micro-server-http/v3 v3.2.4
github.com/unistack-org/micro-server-tcp/v3 v3.2.2 github.com/unistack-org/micro-server-tcp/v3 v3.2.2
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.1.1 github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.1.1
github.com/unistack-org/micro/v3 v3.2.8 github.com/unistack-org/micro/v3 v3.2.8

4
go.sum
View File

@ -551,8 +551,8 @@ github.com/unistack-org/micro-router-register/v3 v3.2.2 h1:lYCymDHkJfhZWYQ4+Sb7F
github.com/unistack-org/micro-router-register/v3 v3.2.2/go.mod h1:Y9Qtlg4NHqq5rR6X6Jm+04LoSJMi7/OOCm2mRueZYTE= github.com/unistack-org/micro-router-register/v3 v3.2.2/go.mod h1:Y9Qtlg4NHqq5rR6X6Jm+04LoSJMi7/OOCm2mRueZYTE=
github.com/unistack-org/micro-server-grpc/v3 v3.2.2 h1:LfjFdl5jYYGY2SgCEH2qObvlNZ6ENC4HSa36uvI/sx4= github.com/unistack-org/micro-server-grpc/v3 v3.2.2 h1:LfjFdl5jYYGY2SgCEH2qObvlNZ6ENC4HSa36uvI/sx4=
github.com/unistack-org/micro-server-grpc/v3 v3.2.2/go.mod h1:459FWPnuW56+gmI3R9ZbWsGEc/+nR70c3YyaI1nRwN8= github.com/unistack-org/micro-server-grpc/v3 v3.2.2/go.mod h1:459FWPnuW56+gmI3R9ZbWsGEc/+nR70c3YyaI1nRwN8=
github.com/unistack-org/micro-server-http/v3 v3.2.3 h1:zrot1162Elq3doCPi/OlcCrqL+QCLxHFlKn/lA0i8iU= github.com/unistack-org/micro-server-http/v3 v3.2.4 h1:Zko5UUqRVnNyPKarHSEgvV1GzPWXxEiNnbFhCfNxt9Y=
github.com/unistack-org/micro-server-http/v3 v3.2.3/go.mod h1:TOeb0O65cr+MYL1l+AAnaprhuSKqeqDoIEuEk5wepAg= github.com/unistack-org/micro-server-http/v3 v3.2.4/go.mod h1:TOeb0O65cr+MYL1l+AAnaprhuSKqeqDoIEuEk5wepAg=
github.com/unistack-org/micro-server-tcp/v3 v3.2.2 h1:2/Xn+4+dnzY/tpD3MgLO1wg3ect9Jx5CLSDfPBjdjT4= github.com/unistack-org/micro-server-tcp/v3 v3.2.2 h1:2/Xn+4+dnzY/tpD3MgLO1wg3ect9Jx5CLSDfPBjdjT4=
github.com/unistack-org/micro-server-tcp/v3 v3.2.2/go.mod h1:TQDIck2+RdEAGIRnwv+2a0OVBUTkL6OM7YUY4AjFFmY= github.com/unistack-org/micro-server-tcp/v3 v3.2.2/go.mod h1:TQDIck2+RdEAGIRnwv+2a0OVBUTkL6OM7YUY4AjFFmY=
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.1.1 h1:sEnPLn3BGt/t+ITsMJ8zHwtDUV9Qty3NIadOa099uHk= github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.1.1 h1:sEnPLn3BGt/t+ITsMJ8zHwtDUV9Qty3NIadOa099uHk=

View File

@ -64,11 +64,20 @@ func TestNativeClientServer(t *testing.T) {
reg := memory.NewRegister() reg := memory.NewRegister()
ctx := context.Background() ctx := context.Background()
var mwfOk bool
mwf := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mwfOk = true
next.ServeHTTP(w, r)
})
}
// create server // create server
srv := httpsrv.NewServer( srv := httpsrv.NewServer(
server.Name("helloworld"), server.Name("helloworld"),
server.Register(reg), server.Register(reg),
server.Codec("application/json", jsonpbcodec.NewCodec()), server.Codec("application/json", jsonpbcodec.NewCodec()),
httpsrv.Middleware(mwf),
//server.WrapHandler(NewServerHandlerWrapper()), //server.WrapHandler(NewServerHandlerWrapper()),
) )
@ -112,6 +121,10 @@ func TestNativeClientServer(t *testing.T) {
if rsp.Rsp != "name_my_name" { if rsp.Rsp != "name_my_name" {
t.Fatalf("invalid response: %#+v\n", rsp) t.Fatalf("invalid response: %#+v\n", rsp)
} }
if !mwfOk {
t.Fatalf("http middleware not works")
}
// stop server // stop server
if err := srv.Stop(); err != nil { if err := srv.Stop(); err != nil {
t.Fatal(err) t.Fatal(err)