Files
sablier/internal/api/api_test.go
Alexis Couvreur fca9c79289 refactor: reorganize code structure (#556)
* refactor: rename providers to Provider

* refactor folders

* fix build cmd

* fix build cmd

* fix build cmd

* fix cmd start
2025-03-10 14:11:40 -04:00

44 lines
1.1 KiB
Go

package api
import (
"github.com/gin-gonic/gin"
"github.com/neilotoole/slogt"
config2 "github.com/sablierapp/sablier/pkg/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 *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 = &ServeStrategy{
Theme: th,
Sablier: mock,
StrategyConfig: config2.NewStrategyConfig(),
SessionsConfig: config2.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
}