blwatest

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package blwatest provides test helpers for blwa applications.

It constructs the identical DI graph as blwa.NewApp but uses fxtest.App which fails the test immediately on DI errors.

Example:

blwatest.SetBaseEnv(t, 18081)
app := blwatest.New[TestEnv](t, routing, blwa.WithAWSClient(...))
app.RequireStart()
t.Cleanup(app.RequireStop)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallHandler added in v0.7.2

func CallHandler(handler bhttp.HandlerFunc, req *http.Request) *httptest.ResponseRecorder

CallHandler invokes a bhttp.HandlerFunc with a buffered response writer and returns the recorded response. It handles the boilerplate of wrapping httptest.ResponseRecorder in a bhttp.ResponseWriter and flushing the buffer afterward.

Types

type App

type App struct {
	*fxtest.App
}

App embeds *fxtest.App for testing blwa applications.

func New

func New[E blwa.Environment](t testing.TB, routing any, opts ...blwa.Option) *App

New creates a test app with the same DI graph as blwa.NewApp.

type Env

type Env struct {
	// contains filtered or unexported fields
}

Env provides a chainable builder for setting blwa.BaseEnvironment env vars via t.Setenv. Create one with SetBaseEnv.

func SetBaseEnv

func SetBaseEnv(t testing.TB, port int) *Env

SetBaseEnv sets all blwa.BaseEnvironment env vars to sensible test defaults. Port is required because each test must use a unique port to avoid collisions.

Defaults:

  • BW_SERVICE_NAME: "test"
  • AWS_LWA_READINESS_CHECK_PATH: "/health"
  • AWS_REGION: "us-east-1"
  • BW_PRIMARY_REGION: "eu-west-1"
  • BW_LAMBDA_TIMEOUT: "30s"
  • AWS_LWA_ERROR_STATUS_CODES: "500-599"
  • OTEL_SDK_DISABLED: "true"
  • AWS_ACCESS_KEY_ID: "test"
  • AWS_SECRET_ACCESS_KEY: "test"

Use the returned Env to override individual values:

blwatest.SetBaseEnv(t, 18085).AWSRegion("eu-west-1").PrimaryRegion("eu-central-1")

func (*Env) AWSRegion

func (e *Env) AWSRegion(region string) *Env

AWSRegion overrides AWS_REGION.

func (*Env) LambdaTimeout

func (e *Env) LambdaTimeout(d string) *Env

LambdaTimeout overrides BW_LAMBDA_TIMEOUT.

func (*Env) PrimaryRegion

func (e *Env) PrimaryRegion(region string) *Env

PrimaryRegion overrides BW_PRIMARY_REGION.

func (*Env) ReadinessCheckPath

func (e *Env) ReadinessCheckPath(path string) *Env

ReadinessCheckPath overrides AWS_LWA_READINESS_CHECK_PATH.

func (*Env) ServiceName

func (e *Env) ServiceName(name string) *Env

ServiceName overrides BW_SERVICE_NAME.

Jump to

Keyboard shortcuts

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