forked from swaggo/http-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger_test.go
41 lines (30 loc) · 989 Bytes
/
swagger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package httpSwagger
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/go-chi/chi"
"github.com/stretchr/testify/assert"
_ "github.com/erply/http-swagger/example/go-chi/docs"
)
func TestWrapHandler(t *testing.T) {
router := chi.NewRouter()
router.Get("/*", WrapHandler)
w1 := performRequest("GET", "/index.html", router)
assert.Equal(t, 200, w1.Code)
w2 := performRequest("GET", "/doc.json", router)
assert.Equal(t, 200, w2.Code)
assert.Equal(t, "application/json; charset=utf-8", w2.Header().Get("content-type"))
w3 := performRequest("GET", "/favicon-16x16.png", router)
assert.Equal(t, 200, w3.Code)
w4 := performRequest("GET", "/notfound", router)
assert.Equal(t, 404, w4.Code)
w5 := performRequest("GET", "/", router)
assert.Equal(t, 301, w5.Code)
}
func performRequest(method, target string, h http.Handler) *httptest.ResponseRecorder {
r := httptest.NewRequest(method, target, nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
return w
}