From 2b1466e41ea4b9c1407e8c5383134f91bc165ef3 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 21 Aug 2020 23:09:35 +0800 Subject: [PATCH] add more tests --- rest/engine.go | 2 +- rest/httpx/responses_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rest/engine.go b/rest/engine.go index 69496868..7f3f6969 100644 --- a/rest/engine.go +++ b/rest/engine.go @@ -209,6 +209,6 @@ func (s *engine) use(middleware Middleware) { func convertMiddleware(ware Middleware) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { - return http.HandlerFunc(ware(next.ServeHTTP)) + return ware(next.ServeHTTP) } } diff --git a/rest/httpx/responses_test.go b/rest/httpx/responses_test.go index 7c19406c..fdb23578 100644 --- a/rest/httpx/responses_test.go +++ b/rest/httpx/responses_test.go @@ -1,6 +1,7 @@ package httpx import ( + "errors" "net/http" "strings" "testing" @@ -17,6 +18,24 @@ func init() { logx.Disable() } +func TestError(t *testing.T) { + const body = "foo" + w := tracedResponseWriter{ + headers: make(map[string][]string), + } + Error(&w, errors.New(body)) + assert.Equal(t, http.StatusBadRequest, w.code) + assert.Equal(t, body, strings.TrimSpace(w.builder.String())) +} + +func TestOk(t *testing.T) { + w := tracedResponseWriter{ + headers: make(map[string][]string), + } + Ok(&w) + assert.Equal(t, http.StatusOK, w.code) +} + func TestOkJson(t *testing.T) { w := tracedResponseWriter{ headers: make(map[string][]string),