Files
sablier/internal/api/api_test.go
Alexis Couvreur 00cc153d7a fix: add http error responses (#494)
This features adds rfc7807 Problem detail responses when an error happens processing a request.

This will greatly improve the common issues  with "blank pages" and "404 pages" issues which should now properly tell the user what input was wrong (group that does not exist, container name that does not exist, etc.)
2025-02-02 00:00:49 -05:00

44 lines
1.1 KiB
Go

package api
import (
"github.com/gin-gonic/gin"
"github.com/sablierapp/sablier/app/http/routes"
"github.com/sablierapp/sablier/app/sessions/sessionstest"
"github.com/sablierapp/sablier/app/theme"
"github.com/sablierapp/sablier/config"
"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 *sessionstest.MockManager) {
t.Helper()
gin.SetMode(gin.TestMode)
ctrl := gomock.NewController(t)
th, err := theme.New()
assert.NilError(t, err)
app = gin.New()
router = app.Group("/api")
mock = sessionstest.NewMockManager(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
}