43 lines
864 B
Go
43 lines
864 B
Go
package server
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
|
|
"code.thetadev.de/TSGRain/WebUI/src/config"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type testServer struct {
|
|
srv *WebUIServer
|
|
router *gin.Engine
|
|
}
|
|
|
|
func newTestServer() *testServer {
|
|
return newTestServerCfg(config.GetDefault())
|
|
}
|
|
|
|
func newTestServerCfg(cfg *config.Config) *testServer {
|
|
sebraucServer := NewServer(cfg)
|
|
router := sebraucServer.getRouter()
|
|
|
|
return &testServer{
|
|
srv: sebraucServer,
|
|
router: router,
|
|
}
|
|
}
|
|
|
|
func (srv *testServer) testRequest(t assert.TestingT, method string, url string,
|
|
body io.Reader, contentType string,
|
|
) *httptest.ResponseRecorder {
|
|
req, err := http.NewRequest(method, url, body)
|
|
req.Header.Set("Content-Type", contentType)
|
|
assert.Nil(t, err)
|
|
|
|
w := httptest.NewRecorder()
|
|
srv.router.ServeHTTP(w, req)
|
|
|
|
return w
|
|
}
|