apptest

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 34 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 NewTestAppWithDB

func NewTestAppWithDB(t testing.TB, db *bun.DB, options ...fx.Option) (*app.App, func())

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.

func (*NopConfig) Unmarshal

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

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

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

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

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) SetupAppWithDB

func (s *Suite) SetupAppWithDB(db *bun.DB, opts ...fx.Option)

SetupAppWithDB creates a test app using an existing *bun.DB instead of creating a new database connection.

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