WebUI/src/server/server_test.go
Theta-Dev 60034b4815
All checks were successful
continuous-integration/drone/push Build is passing
add server base
2022-02-01 23:08:45 +01:00

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
}