From d1590d274bb87259f37dc1a4e8c9a39bf22b6453 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 7 Feb 2021 13:31:39 +0300 Subject: [PATCH] add tests for http middlewares Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- go.sum | 4 ++-- server/http/http_test.go | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e5ad851..fa3eadc 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( 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-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-wrapper-trace-opentracing/v3 v3.1.1 github.com/unistack-org/micro/v3 v3.2.8 diff --git a/go.sum b/go.sum index 7f4d33e..3e01f62 100644 --- a/go.sum +++ b/go.sum @@ -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-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-http/v3 v3.2.3 h1:zrot1162Elq3doCPi/OlcCrqL+QCLxHFlKn/lA0i8iU= -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 h1:Zko5UUqRVnNyPKarHSEgvV1GzPWXxEiNnbFhCfNxt9Y= +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/go.mod h1:TQDIck2+RdEAGIRnwv+2a0OVBUTkL6OM7YUY4AjFFmY= github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.1.1 h1:sEnPLn3BGt/t+ITsMJ8zHwtDUV9Qty3NIadOa099uHk= diff --git a/server/http/http_test.go b/server/http/http_test.go index ec6c4cc..a206984 100644 --- a/server/http/http_test.go +++ b/server/http/http_test.go @@ -64,11 +64,20 @@ func TestNativeClientServer(t *testing.T) { reg := memory.NewRegister() 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 srv := httpsrv.NewServer( server.Name("helloworld"), server.Register(reg), server.Codec("application/json", jsonpbcodec.NewCodec()), + httpsrv.Middleware(mwf), //server.WrapHandler(NewServerHandlerWrapper()), ) @@ -112,6 +121,10 @@ func TestNativeClientServer(t *testing.T) { if rsp.Rsp != "name_my_name" { t.Fatalf("invalid response: %#+v\n", rsp) } + + if !mwfOk { + t.Fatalf("http middleware not works") + } // stop server if err := srv.Stop(); err != nil { t.Fatal(err)