Documentation
¶
Index ¶
- func NewTestApp(t testing.TB, options ...fx.Option) (*app.App, func())
- func NewTestAppWithDBConfig(t testing.TB, db *bun.DB, cfg config.DataSourceConfig, 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) SetupAppWithDBConfig(db *bun.DB, cfg config.DataSourceConfig, 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 NewTestAppWithDBConfig ¶ added in v0.27.0
func NewTestAppWithDBConfig( t testing.TB, db *bun.DB, cfg config.DataSourceConfig, options ...fx.Option, ) (*app.App, func())
NewTestAppWithDBConfig creates a test application that uses an existing *bun.DB and the matching primary data source config. Use this for tests that reuse a non-SQLite connection so migration and schema services pick the correct dialect metadata.
Types ¶
type NopConfig ¶
type NopConfig struct{}
NopConfig implements config.Config for testing without file dependencies. It returns nil for every Unmarshal call except vef.data_sources, where it injects a default in-memory SQLite primary so the framework's newDataSourcesConfig (which requires a primary entry) can boot. Tests that need a different primary or extra sources override the result via fx.Replace(&config.DataSourcesConfig{...}).
type Suite ¶
type Suite struct {
suite.Suite
// App is the test application instance, available after SetupApp/SetupAppWithDBConfig.
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. It signs with the same secret and audience (testJWTAudience, derived from testAppName) that apptest's coreOptions configures for the test app, so the token verifies out of the box. The token is valid for 1 hour with no notBefore delay. If a suite overrides the app name via fx.Replace, this method will produce tokens with the wrong audience — use a custom JWTConfig in that case.
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) SetupAppWithDBConfig ¶ added in v0.27.0
SetupAppWithDBConfig creates a test app using an existing *bun.DB and the matching primary data source config.