Documentation
¶
Index ¶
- Constants
- func CreateSnapshotRecord(t *testing.T, ctx context.Context, db *Database, templateID, sandboxID string, ...)
- func CreateTestBuild(t *testing.T, ctx context.Context, db *Database, templateID string, ...) uuid.UUID
- func CreateTestBuildAssignment(t *testing.T, ctx context.Context, db *Database, templateID string, ...)
- func CreateTestTeam(t *testing.T, db *Database) uuid.UUID
- func CreateTestTemplate(t *testing.T, db *Database, teamID uuid.UUID) string
- func CreateTestTemplateAlias(t *testing.T, db *Database, templateID string) string
- func CreateTestTemplateAliasWithName(t *testing.T, db *Database, templateID, aliasName string, namespace *string)
- func CreateTestTemplateAliasWithNamespace(t *testing.T, db *Database, templateID string, namespace *string) string
- func CreateTestTemplateWithAlias(t *testing.T, db *Database, teamID uuid.UUID) (string, string)
- func DeleteTriggerBuildAssignment(t *testing.T, ctx context.Context, db *Database, templateID string, ...)
- func GetBuildStatusGroup(t *testing.T, ctx context.Context, db *Database, buildID uuid.UUID) types.BuildStatusGroup
- func GetEnvBuildByID(t *testing.T, ctx context.Context, db *Database, buildID uuid.UUID) bool
- func GetEnvByID(t *testing.T, ctx context.Context, db *Database, envID string) bool
- func GetSnapshotMetadata(t *testing.T, ctx context.Context, db *Database, sandboxID string) types.JSONBStringMap
- func GetTeamSlug(t *testing.T, ctx context.Context, db *Database, teamID uuid.UUID) string
- func SetNonZero(t *testing.T, v reflect.Value)
- func SnapshotEnvStamp(t *testing.T, ctx context.Context, db *Database, sandboxID string) string
- func SoftDeleteEnvUnstamped(t *testing.T, ctx context.Context, db *Database, envID string)
- func UpsertTestSnapshot(t *testing.T, ctx context.Context, db *Database, templateID, sandboxID string, ...) queries.UpsertSnapshotRow
- func UpsertTestSnapshotWithStatus(t *testing.T, ctx context.Context, db *Database, templateID, sandboxID string, ...) queries.UpsertSnapshotRow
- type BuildAssignment
- type Database
- type QueryRecorder
- func (r *QueryRecorder) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
- func (r *QueryRecorder) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (r *QueryRecorder) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (r *QueryRecorder) Take() []string
Constants ¶
const ( // TrackingTable is goose's bookkeeping table for this database. Exported // because migration tests step the schema through their own provider and // must target the same table the harness migrated. TrackingTable = dbmodule.TrackingTable // EnvDatabaseURL names the environment variable carrying the URL of the // PostgreSQL server the tests share. Each test gets its own database on // it, copied from a migrated template. EnvDatabaseURL = "PG_TEST_DATABASE_URL" )
Variables ¶
This section is empty.
Functions ¶
func CreateSnapshotRecord ¶
func CreateSnapshotRecord(t *testing.T, ctx context.Context, db *Database, templateID, sandboxID string, teamID uuid.UUID, baseTemplateID string)
CreateSnapshotRecord creates just the snapshot record without creating a new build
func CreateTestBuild ¶
func CreateTestBuild(t *testing.T, ctx context.Context, db *Database, templateID string, statusGroup types.BuildStatusGroup) uuid.UUID
CreateTestBuild creates a build for a template with the given status group
func CreateTestBuildAssignment ¶
func CreateTestBuildAssignment(t *testing.T, ctx context.Context, db *Database, templateID string, buildID uuid.UUID, tag string)
CreateTestBuildAssignment creates a build assignment with a specific tag
func CreateTestTeam ¶
CreateTestTeam creates a test team in the database.
func CreateTestTemplate ¶
CreateTestTemplate creates a base env (template) row in the database (required by foreign key constraints in subsequent test inserts).
func CreateTestTemplateAlias ¶
func CreateTestTemplateAliasWithName ¶
func CreateTestTemplateAliasWithName(t *testing.T, db *Database, templateID, aliasName string, namespace *string)
CreateTestTemplateAliasWithName creates an alias with a specific name and optional namespace
func CreateTestTemplateAliasWithNamespace ¶
func CreateTestTemplateAliasWithNamespace(t *testing.T, db *Database, templateID string, namespace *string) string
CreateTestTemplateAliasWithNamespace creates an alias with a specific namespace
func DeleteTriggerBuildAssignment ¶
func DeleteTriggerBuildAssignment(t *testing.T, ctx context.Context, db *Database, templateID string, buildID uuid.UUID, tag string)
DeleteTriggerBuildAssignment deletes a trigger-created build assignment This is useful for tests that need to create builds without the auto-assigned 'default' tag
func GetBuildStatusGroup ¶
func GetBuildStatusGroup(t *testing.T, ctx context.Context, db *Database, buildID uuid.UUID) types.BuildStatusGroup
GetBuildStatusGroup retrieves the status group of a build
func GetEnvBuildByID ¶
GetEnvBuildByID retrieves an env_build by ID to verify it exists
func GetEnvByID ¶
GetEnvByID retrieves an env by ID to verify it exists
func GetSnapshotMetadata ¶
func GetSnapshotMetadata(t *testing.T, ctx context.Context, db *Database, sandboxID string) types.JSONBStringMap
GetSnapshotMetadata retrieves the metadata from a snapshot using raw SQL
func GetTeamSlug ¶
GetTeamSlug retrieves the slug for a team
func SetNonZero ¶
SetNonZero sets v, a settable field of a generated query row, to a value other than its zero, so a test can tell whether code copied that field.
func SnapshotEnvStamp ¶
SnapshotEnvStamp reports how a snapshot's env_deleted_at relates to its own env's deleted_at: "live" (both NULL), "stamped" (equal), "unstamped" (only the env is deleted) or "mismatch".
func SoftDeleteEnvUnstamped ¶
SoftDeleteEnvUnstamped marks an env deleted without stamping its snapshots, the way envs deleted before snapshots.env_deleted_at existed were left.
func UpsertTestSnapshot ¶
func UpsertTestSnapshot(t *testing.T, ctx context.Context, db *Database, templateID, sandboxID string, teamID uuid.UUID, baseTemplateID string) queries.UpsertSnapshotRow
UpsertTestSnapshot creates/updates a snapshot for testing with success status
func UpsertTestSnapshotWithStatus ¶
func UpsertTestSnapshotWithStatus(t *testing.T, ctx context.Context, db *Database, templateID, sandboxID string, teamID uuid.UUID, baseTemplateID string, statusGroup types.BuildStatusGroup) queries.UpsertSnapshotRow
UpsertTestSnapshotWithStatus creates/updates a snapshot with a specific status group
Types ¶
type BuildAssignment ¶
type BuildAssignment struct {
ID uuid.UUID
EnvID string
BuildID uuid.UUID
Tag string
Source string
}
BuildAssignment represents a row from env_build_assignments
func GetBuildAssignmentByBuildID ¶
func GetBuildAssignmentByBuildID(t *testing.T, ctx context.Context, db *Database, buildID uuid.UUID) *BuildAssignment
GetBuildAssignmentByBuildID retrieves a build assignment for a specific build_id
func GetBuildAssignments ¶
func GetBuildAssignments(t *testing.T, ctx context.Context, db *Database, envID string) []BuildAssignment
GetBuildAssignments retrieves all build assignments for a given env_id
type Database ¶
type Database struct {
SqlcClient *db.Client
AuthDb *authdb.Client
AuthDB *authdb.Client
TestQueries *queries.Queries
// contains filtered or unexported fields
}
Database encapsulates the test database and clients
func SetupDatabase ¶
SetupDatabase creates a fresh database with migrations applied on the server EnvDatabaseURL names
func (*Database) RecordedAuthDB ¶
RecordedAuthDB returns an auth client on this test's database whose statements the returned recorder sees. Its Close and transactions are not usable; it serves queries only.
type QueryRecorder ¶
QueryRecorder records the sqlc name of every statement run through it, so a test can count the statements a code path issues.
func (*QueryRecorder) Exec ¶
func (r *QueryRecorder) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
func (*QueryRecorder) Take ¶
func (r *QueryRecorder) Take() []string
Take returns the names recorded since the last call.