echoswagger/examples/main_test.go

26 lines
583 B
Go
Raw Normal View History

2018-09-05 14:06:30 +02:00
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/elvinchan/echoswagger"
"github.com/labstack/echo"
"github.com/stretchr/testify/assert"
)
func TestMain(t *testing.T) {
e := initServer()
req := httptest.NewRequest(echo.GET, "/doc/swagger.json", nil)
rec := httptest.NewRecorder()
c := e.Echo().NewContext(req, rec)
b, err := ioutil.ReadFile("./swagger.json")
assert.Nil(t, err)
if assert.NoError(t, e.(*echoswagger.Root).Spec(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.JSONEq(t, string(b), rec.Body.String())
}
}