testutil

package
v0.0.0-...-89de701 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 60 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(t *testing.T, url string) (*http.Response, error)

Get performs a context-aware GET, replacing http.Get in tests so requests carry the test's context (and satisfy the noctx linter).

func NewMockShopwareServer

func NewMockShopwareServer(t *testing.T) *httptest.Server

NewMockShopwareServer creates a mock Shopware API server that handles OAuth token and info endpoints.

func NewRequest

func NewRequest(t *testing.T, method, url string, body io.Reader) *http.Request

NewRequest builds a context-aware request, replacing http.NewRequest in tests.

func Post

func Post(t *testing.T, url, contentType string, body io.Reader) (*http.Response, error)

Post performs a context-aware POST, replacing http.Post in tests.

Types

type TestEnv

type TestEnv struct {
	Pool    *pgxpool.Pool
	Queries *queries.Queries
	Handler *handler.Handler
	Server  *httptest.Server
	Cfg     *config.Config
	// Mail captures every email sent during the test, in place of real
	// delivery. Use the mailertest assertion helpers against it.
	Mail *mailertest.RecordingTransport
}

TestEnv holds all test dependencies.

func Setup

func Setup(t *testing.T, cfgFn ...func(*config.Config)) *TestEnv

Setup creates a new TestEnv using shared Postgres and Redis containers. Each test gets a clean database via TRUNCATE. Optional cfgFn modifiers are applied to the config before building the handler.

func (*TestEnv) AuthRequest

func (e *TestEnv) AuthRequest(t *testing.T, method, path, token string) *http.Request

AuthRequest creates a new HTTP request with the session token set.

func (*TestEnv) SeedEnvironment

func (e *TestEnv) SeedEnvironment(t *testing.T, orgID string, shopID int, name, url string) int

SeedEnvironment creates a test environment in an organization/shop. It also sets the environment as the shop's default if none is set.

func (*TestEnv) SeedMember

func (e *TestEnv) SeedMember(t *testing.T, orgID, userID, role string)

SeedMember adds a user to an existing organization with an explicit role. SeedOrganization always creates an owner, so this is what makes role-gated behaviour (member vs owner/admin) testable.

func (*TestEnv) SeedNotification

func (e *TestEnv) SeedNotification(t *testing.T, userID, key, level, title, message string) int

SeedNotification creates a test notification for a user.

func (*TestEnv) SeedOrganization

func (e *TestEnv) SeedOrganization(t *testing.T, orgID, name, slug, userID string)

SeedOrganization creates a test organization and adds the user as a member.

func (*TestEnv) SeedShop

func (e *TestEnv) SeedShop(t *testing.T, orgID, name string) int

SeedShop creates a test shop in an organization.

func (*TestEnv) SeedUser

func (e *TestEnv) SeedUser(t *testing.T, id, name, email, role string) string

SeedUser creates a test user and session, returning the session token.

Directories

Path Synopsis
Package testdb provides a shared PostgreSQL testcontainer with the shopmon schema applied.
Package testdb provides a shared PostgreSQL testcontainer with the shopmon schema applied.

Jump to

Keyboard shortcuts

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