Documentation
¶
Index ¶
- func NewTestApp(t testing.TB, options ...fx.Option) (*app.App, func())
- func NewTestAppWithDB(t testing.TB, db *bun.DB, options ...fx.Option) (*app.App, func())
- type NopConfig
- type Suite
- func (s *Suite) GenerateToken(principal *security.Principal) string
- func (s *Suite) MakeRESTRequest(method, path, body string) *http.Response
- func (s *Suite) MakeRESTRequestWithToken(method, path, body, token string) *http.Response
- func (s *Suite) MakeRPCRequest(body api.Request) *http.Response
- func (s *Suite) MakeRPCRequestWithToken(body api.Request, token string) *http.Response
- func (s *Suite) ReadDataAsMap(data any) map[string]any
- func (s *Suite) ReadDataAsSlice(data any) []any
- func (s *Suite) ReadResult(resp *http.Response) result.Result
- func (s *Suite) SetupApp(opts ...fx.Option)
- func (s *Suite) SetupAppWithDB(db *bun.DB, opts ...fx.Option)
- func (s *Suite) TearDownApp()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTestApp ¶
NewTestApp creates a test application with Fx dependency injection. Returns the app instance and a cleanup function.
func NewTestAppWithDB ¶
NewTestAppWithDB creates a test application that uses an existing *bun.DB instead of creating a new connection via database.Module. This avoids redundant database connections when tests already manage their own.
Types ¶
type NopConfig ¶
type NopConfig struct{}
NopConfig implements config.Config for testing without file dependencies.
type Suite ¶
type Suite struct {
suite.Suite
// App is the test application instance, available after SetupApp/SetupAppWithDB.
App *app.App
// contains filtered or unexported fields
}
Suite provides common integration test infrastructure for suites that boot a full FX App and make HTTP requests against it. Embed this struct instead of suite.Suite to get app lifecycle management, RPC/REST request helpers, response parsing, and JWT token generation.
func (*Suite) GenerateToken ¶
GenerateToken creates a valid JWT access token for the given principal. Uses security.DefaultJWTSecret and the test app audience ("test_app"). The token is valid for 1 hour with no notBefore delay.
Tests using this method must configure the same JWT secret in their FX app:
fx.Replace(&security.JWTConfig{Secret: security.DefaultJWTSecret, Audience: "test_app"})
func (*Suite) MakeRESTRequest ¶
MakeRESTRequest sends a REST API request with the given HTTP method, path, and optional JSON body.
func (*Suite) MakeRESTRequestWithToken ¶
MakeRESTRequestWithToken sends a REST API request with a Bearer authorization header.
func (*Suite) MakeRPCRequest ¶
MakeRPCRequest sends an RPC API request (POST /api with JSON body) and returns the raw HTTP response.
func (*Suite) MakeRPCRequestWithToken ¶
MakeRPCRequestWithToken sends an RPC API request with a Bearer authorization header.
func (*Suite) ReadDataAsMap ¶
ReadDataAsMap asserts that data is a map[string]any and returns it.
func (*Suite) ReadDataAsSlice ¶
ReadDataAsSlice asserts that data is a []any and returns it.
func (*Suite) ReadResult ¶
ReadResult reads and decodes the HTTP response body as result.Result. The response body is closed after reading.
func (*Suite) SetupAppWithDB ¶
SetupAppWithDB creates a test app using an existing *bun.DB instead of creating a new database connection.