Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ubogdan committed Oct 27, 2021
1 parent 4e39893 commit b249fb9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,29 @@ func TestWrapHandler(t *testing.T) {
assert.Equal(t, 301, w7.Code)
}

func TestHandlerReuse(t *testing.T) {
router := echo.New()

router.GET("/swagger/*", EchoWrapHandler())
router.GET("/admin/swagger/*", EchoWrapHandler())

w1 := performRequest("GET", "/swagger/index.html", router)
assert.Equal(t, 200, w1.Code)
assert.Equal(t, w1.Header()["Content-Type"][0], "text/html; charset=utf-8")

w2 := performRequest("GET", "/admin/swagger/index.html", router)
assert.Equal(t, 200, w2.Code)
assert.Equal(t, w2.Header()["Content-Type"][0], "text/html; charset=utf-8")

w3 := performRequest("GET", "/swagger/index.html", router)
assert.Equal(t, 200, w3.Code)
assert.Equal(t, w3.Header()["Content-Type"][0], "text/html; charset=utf-8")

w4 := performRequest("GET", "/admin/swagger/index.html", router)
assert.Equal(t, 200, w4.Code)
assert.Equal(t, w4.Header()["Content-Type"][0], "text/html; charset=utf-8")
}

func performRequest(method, target string, e *echo.Echo) *httptest.ResponseRecorder {
r := httptest.NewRequest(method, target, nil)
w := httptest.NewRecorder()
Expand Down

0 comments on commit b249fb9

Please sign in to comment.