Add Swagger consistency check
This commit is contained in:
parent
42c319c12c
commit
e63876053f
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,29 @@
|
|||
package docs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http/httptest"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func TestServe(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
ctx, _ := gin.CreateTestContext(recorder)
|
||||
ctx.Request = httptest.NewRequest("GET", "/swagger", nil)
|
||||
ctx.Request.URL.Host = "localhost"
|
||||
|
||||
Serve(ctx)
|
||||
|
||||
actualFileContent := getActualSpecFileContent(t)
|
||||
packrFileContent := recorder.Body.String()
|
||||
assert.JSONEq(t, packrFileContent, actualFileContent, "packr and spec file are out of sync")
|
||||
}
|
||||
|
||||
func getActualSpecFileContent(t *testing.T) string {
|
||||
bytes, err := ioutil.ReadFile("spec.json")
|
||||
assert.Nil(t, err)
|
||||
return string(bytes)
|
||||
}
|
||||
Loading…
Reference in New Issue