apptest

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestApp

func NewTestApp(t testing.TB, options ...fx.Option) (*app.App, func())

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{...}).

func (*NopConfig) Unmarshal

func (*NopConfig) Unmarshal(key string, target any) error

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

func (s *Suite) GenerateToken(principal *security.Principal) string

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

func (s *Suite) MakeRESTRequest(method, path, body string) *http.Response

MakeRESTRequest sends a REST API request with the given HTTP method, path, and optional JSON body.

func (*Suite) MakeRESTRequestWithToken

func (s *Suite) MakeRESTRequestWithToken(method, path, body, token string) *http.Response

MakeRESTRequestWithToken sends a REST API request with a Bearer authorization header.

func (*Suite) MakeRPCRequest

func (s *Suite) MakeRPCRequest(body api.Request) *http.Response

MakeRPCRequest sends an RPC API request (POST /api with JSON body) and returns the raw HTTP response.

func (*Suite) MakeRPCRequestWithToken

func (s *Suite) MakeRPCRequestWithToken(body api.Request, token string) *http.Response

MakeRPCRequestWithToken sends an RPC API request with a Bearer authorization header.

func (*Suite) ReadDataAsMap

func (s *Suite) ReadDataAsMap(data any) map[string]any

ReadDataAsMap asserts that data is a map[string]any and returns it.

func (*Suite) ReadDataAsSlice

func (s *Suite) ReadDataAsSlice(data any) []any

ReadDataAsSlice asserts that data is a []any and returns it.

func (*Suite) ReadResult

func (s *Suite) ReadResult(resp *http.Response) result.Result

ReadResult reads and decodes the HTTP response body as result.Result. The response body is closed after reading.

func (*Suite) SetupApp

func (s *Suite) SetupApp(opts ...fx.Option)

SetupApp creates a test app with the given FX options.

func (*Suite) SetupAppWithDBConfig added in v0.27.0

func (s *Suite) SetupAppWithDBConfig(db *bun.DB, cfg config.DataSourceConfig, opts ...fx.Option)

SetupAppWithDBConfig creates a test app using an existing *bun.DB and the matching primary data source config.

func (*Suite) TearDownApp

func (s *Suite) TearDownApp()

TearDownApp stops the app gracefully.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL