Documentation
¶
Overview ¶
Package agenttest provides helpers for testing agents built on agentsdk. It lives in its own package so the testing dependency it pulls in never reaches an agent's production binary — agents import it only from _test.go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UseDB ¶
UseDB points the agent at the test database named by $TEST_DB_URL and brings its schema to a clean, fully-migrated state. It skips the test when $TEST_DB_URL is unset, so DB-backed tests run only where a test database is provisioned (the agent build environment sets it).
It sets AIRLOCK_DB_URL (so agent.DB() connects there), then resets the schema — goose down to 0, then up — applying db/migrations. Go migrations run with the agent attached, exactly as in production. Call it after constructing the agent and before using agent.DB():
env := agenttest.NewEnv(t) a := newAgent() agenttest.UseDB(t, a) // a.DB() now points at a freshly migrated test schema
Types ¶
type Env ¶
type Env struct {
// Airlock is the mock Airlock server. Inspect Airlock.Requests() to
// assert on the calls a handler made.
Airlock *agentsdk.MockAirlock
// URL is the mock Airlock's base URL (also set as AIRLOCK_API_URL).
URL string
}
Env is a test environment for an agent: a mock Airlock server plus the AIRLOCK_* environment variables wired to point at it.
func NewEnv ¶
NewEnv starts a mock Airlock and sets the environment variables agentsdk.New requires (AIRLOCK_API_URL, AIRLOCK_AGENT_ID, AIRLOCK_AGENT_TOKEN) to point at it. Call it before constructing the agent. The mock server and the env vars are torn down automatically when the test ends.
When a test database is provisioned ($TEST_DB_URL), NewEnv also sets AIRLOCK_DB_URL to it — up front, before the caller builds the agent — so an agent that caches agent.DB() in its Deps at construction (the recommended pattern) gets a live handle, exactly as in production. agenttest.UseDB then resets and migrates that schema. Without $TEST_DB_URL the var stays unset and UseDB skips the test.