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

View File

@@ -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)