+4
-19
@@ -5,7 +5,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-contrib/gzip"
|
"github.com/gin-contrib/gzip"
|
||||||
@@ -23,17 +22,6 @@ func (s *mockedSwag) ReadDoc() string {
|
|||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
once sync.Once
|
|
||||||
doc = &mockedSwag{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func regDoc() {
|
|
||||||
once.Do(func() {
|
|
||||||
swag.Register(swag.Name, doc)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWrapHandler(t *testing.T) {
|
func TestWrapHandler(t *testing.T) {
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
@@ -44,8 +32,6 @@ func TestWrapHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWrapCustomHandler(t *testing.T) {
|
func TestWrapCustomHandler(t *testing.T) {
|
||||||
regDoc()
|
|
||||||
|
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
|
|
||||||
@@ -55,7 +41,10 @@ func TestWrapCustomHandler(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusOK, w1.Code)
|
assert.Equal(t, http.StatusOK, w1.Code)
|
||||||
assert.Equal(t, w1.Header()["Content-Type"][0], "text/html; charset=utf-8")
|
assert.Equal(t, w1.Header()["Content-Type"][0], "text/html; charset=utf-8")
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, performRequest(http.MethodGet, "/doc.json", router).Code)
|
assert.Equal(t, http.StatusInternalServerError, performRequest(http.MethodGet, "/doc.json", router).Code)
|
||||||
|
|
||||||
|
doc := &mockedSwag{}
|
||||||
|
swag.Register(swag.Name, doc)
|
||||||
|
|
||||||
w2 := performRequest(http.MethodGet, "/doc.json", router)
|
w2 := performRequest(http.MethodGet, "/doc.json", router)
|
||||||
assert.Equal(t, http.StatusOK, w2.Code)
|
assert.Equal(t, http.StatusOK, w2.Code)
|
||||||
@@ -86,8 +75,6 @@ func TestWrapCustomHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDisablingWrapHandler(t *testing.T) {
|
func TestDisablingWrapHandler(t *testing.T) {
|
||||||
regDoc()
|
|
||||||
|
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
@@ -129,8 +116,6 @@ func TestDisablingCustomWrapHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWithGzipMiddleware(t *testing.T) {
|
func TestWithGzipMiddleware(t *testing.T) {
|
||||||
regDoc()
|
|
||||||
|
|
||||||
gin.SetMode(gin.TestMode)
|
gin.SetMode(gin.TestMode)
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user