Add Swagger consistency check

This commit is contained in:
Jannis Mattheis 2018-02-27 20:10:38 +01:00 committed by Jannis Mattheis
parent 42c319c12c
commit e63876053f
2 changed files with 30 additions and 0 deletions

File diff suppressed because one or more lines are too long

29
docs/swagger_test.go Normal file
View File

@ -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)
}