Browse Source

add more tests

kevin 4 years ago
parent
commit
2b1466e41e
2 changed files with 20 additions and 1 deletions
  1. 1 1
      rest/engine.go
  2. 19 0
      rest/httpx/responses_test.go

+ 1 - 1
rest/engine.go

@@ -209,6 +209,6 @@ func (s *engine) use(middleware Middleware) {
 
 
 func convertMiddleware(ware Middleware) func(http.Handler) http.Handler {
 func convertMiddleware(ware Middleware) func(http.Handler) http.Handler {
 	return func(next http.Handler) http.Handler {
 	return func(next http.Handler) http.Handler {
-		return http.HandlerFunc(ware(next.ServeHTTP))
+		return ware(next.ServeHTTP)
 	}
 	}
 }
 }

+ 19 - 0
rest/httpx/responses_test.go

@@ -1,6 +1,7 @@
 package httpx
 package httpx
 
 
 import (
 import (
+	"errors"
 	"net/http"
 	"net/http"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
@@ -17,6 +18,24 @@ func init() {
 	logx.Disable()
 	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) {
 func TestOkJson(t *testing.T) {
 	w := tracedResponseWriter{
 	w := tracedResponseWriter{
 		headers: make(map[string][]string),
 		headers: make(map[string][]string),