mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-21 21:33:06 +01:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/neilotoole/slogt"
|
|
"github.com/sablierapp/sablier/app/http/routes"
|
|
"github.com/sablierapp/sablier/config"
|
|
"github.com/sablierapp/sablier/pkg/sablier/sabliertest"
|
|
"github.com/sablierapp/sablier/pkg/theme"
|
|
"go.uber.org/mock/gomock"
|
|
"gotest.tools/v3/assert"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func NewApiTest(t *testing.T) (app *gin.Engine, router *gin.RouterGroup, strategy *routes.ServeStrategy, mock *sabliertest.MockSablier) {
|
|
t.Helper()
|
|
gin.SetMode(gin.TestMode)
|
|
ctrl := gomock.NewController(t)
|
|
th, err := theme.New(slogt.New(t))
|
|
assert.NilError(t, err)
|
|
|
|
app = gin.New()
|
|
router = app.Group("/api")
|
|
mock = sabliertest.NewMockSablier(ctrl)
|
|
strategy = &routes.ServeStrategy{
|
|
Theme: th,
|
|
SessionsManager: mock,
|
|
StrategyConfig: config.NewStrategyConfig(),
|
|
SessionsConfig: config.NewSessionsConfig(),
|
|
}
|
|
|
|
return app, router, strategy, mock
|
|
}
|
|
|
|
// PerformRequest runs an API request with an empty request body.
|
|
func PerformRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
|
|
req, _ := http.NewRequest(method, path, nil)
|
|
w := httptest.NewRecorder()
|
|
r.ServeHTTP(w, req)
|
|
|
|
return w
|
|
}
|