Help us shape the future of Go! Take the 2026 Go Developer Survey

storetest

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package storetest opens the Postgres-backed store for tests. Tests that need a database skip unless INNERWALL_TEST_DATABASE_URL is set; CI sets it to a service container, and the local loop sets it to whatever Postgres the developer has.

Index

Constants

View Source
const EnvDatabaseURL = "INNERWALL_TEST_DATABASE_URL"

EnvDatabaseURL names the environment variable that points tests at a database. The database is migrated and every table emptied before each test that opens it, so it must be disposable.

View Source
const RetiredHost = "batch-prod-01"

RetiredHost is the hostname of the workload SeedRetired retires.

Variables

View Source
var FleetNow = time.Date(2026, 9, 13, 12, 0, 0, 0, time.UTC)

FleetNow is the fixed clock SeedFleet seeds against.

Functions

func Open

func Open(t *testing.T) *store.Store

Open migrates the test database, empties every table, and returns an open store. It skips the test when no database is configured. The database is held exclusively until the test ends.

func Reset

func Reset(ctx context.Context, url string) error

Reset migrates the database at url and empties every table, so what follows starts from nothing. It is a fixture, not a production query, and the database must be disposable: the test loop and the development seed command are its only callers.

func SeedEstate

func SeedEstate(ctx context.Context, s *store.Store, f *Fleet, extra int) error

SeedEstate adds a review estate to a fleet Seed has loaded: the label groups, address groups, modes, and traffic of the flow map's design (a few hundred workloads under ten app labels plus thirty unlabeled ones, two address groups, and unknown sources), so the map and the fleet can be reviewed at the shape they were designed for. extra adds that many more app groups of three workloads each, every one reached by the storefront API, to exercise the map at estate scale. Every instant is relative to f.Now. It is development data only; no test asserts on its shape beyond that it loads.

func SeedRetired added in v0.5.0

func SeedRetired(ctx context.Context, s *store.Store, f *Fleet) (identity.WorkloadID, error)

SeedRetired adds one retired workload to a fleet Seed has loaded, for reviewing the console's retired state against a running control plane: batch-prod-01 (app=batch, env=prod, tier=worker), a decommissioned batch host whose agent was last heard from thirty hours before f.Now, retired four hours after that through the domain function the command line and the operator surface call, with its credential lapsed since. No rule names its labels, so no other workload's policy moves. It is development data only, loaded by the dev seed command beside the review estate.

Types

type Fleet

type Fleet struct {
	Now   time.Time
	Token enroll.Token
	// RevokedToken and ExpiredToken enrolled nothing.
	RevokedToken, ExpiredToken enroll.Token
	Web                        identity.WorkloadID
	DB                         identity.WorkloadID
	Cache                      identity.WorkloadID
	// Addresses of the three workloads.
	WebAddr, DBAddr, CacheAddr netip.Addr
	Office                     policy.AddressGroup
	Ruleset                    policy.Ruleset
	// DBRuleID is the rendered rule on db-1 admitting web-1 on tcp/5432.
	DBRuleID string
	// DBVersion is db-1's latest rendered version.
	DBVersion uint64
	// Window1 and Window2 are the two reporting windows, five minutes
	// each, starting two hours and one hour before Now.
	Window1, Window2 time.Time
	// WindowLength is the length of each window.
	WindowLength time.Duration
}

Fleet is the seeded estate SeedFleet builds: three workloads in three states, one address group, one ruleset rendered onto them, and two reporting windows of flows that produce recognizable screen states (a populated rollup with would-block traffic, a degraded workload, an offline one). Every instant is relative to Now, a fixed clock, so a test that reads the seed sets its own clock to Now.

  • web-1 (role=web, env=prod): enforced, synced, healthy. Its only inbound traffic is blocked: no rule admits it.
  • db-1 (role=db, env=prod): simulation, degraded (the agent refused an apply), renewal failing, dropping flow records. Admits web-1 on tcp/5432 by the ruleset; sees would-block traffic from the office group, an unknown address, and web-1 on tcp/22.
  • cache-1 (role=cache, env=prod): visibility, offline for three hours, credential expired. Observes web-1 on tcp/6379.

Three provisioning tokens give the token listing each of its states: "prod", valid and the one every workload enrolled with, minted before listing hints were kept so it lists without one; "legacy-import", revoked; and "staging-trial", expired unused. Only "prod" enrolled anything.

func Seed

func Seed(ctx context.Context, s *store.Store, now time.Time) (*Fleet, error)

Seed populates s with the fleet described on Fleet, every instant relative to now. The store must be empty. It is the one implementation behind SeedFleet and the development seed command, so a review against a running control plane sees the same estate the tests do.

func SeedFleet

func SeedFleet(t *testing.T, s *store.Store) *Fleet

SeedFleet populates s with the fleet described on Fleet, relative to FleetNow. The store must be empty.

Jump to

Keyboard shortcuts

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