testutils

package
v0.0.0-...-30723ed Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

func CreateTestTeam(t *testing.T, db *Database) uuid.UUID

CreateTestTeam creates a test team in the database.

func CreateTestTemplate

func CreateTestTemplate(t *testing.T, db *Database, teamID uuid.UUID) string

CreateTestTemplate creates a base env (template) row in the database (required by foreign key constraints in subsequent test inserts).

func CreateTestTemplateAlias

func CreateTestTemplateAlias(t *testing.T, db *Database, templateID string) string

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 CreateTestTemplateWithAlias

func CreateTestTemplateWithAlias(t *testing.T, db *Database, teamID uuid.UUID) (string, string)

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

func GetEnvBuildByID(t *testing.T, ctx context.Context, db *Database, buildID uuid.UUID) bool

GetEnvBuildByID retrieves an env_build by ID to verify it exists

func GetEnvByID

func GetEnvByID(t *testing.T, ctx context.Context, db *Database, envID string) bool

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

func GetTeamSlug(t *testing.T, ctx context.Context, db *Database, teamID uuid.UUID) string

GetTeamSlug retrieves the slug for a team

func SetNonZero

func SetNonZero(t *testing.T, v reflect.Value)

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

func SnapshotEnvStamp(t *testing.T, ctx context.Context, db *Database, sandboxID string) string

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

func SoftDeleteEnvUnstamped(t *testing.T, ctx context.Context, db *Database, envID string)

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

func SetupDatabase(t *testing.T) *Database

SetupDatabase creates a fresh database with migrations applied on the server EnvDatabaseURL names

func (*Database) ConnStr

func (db *Database) ConnStr() string

func (*Database) RecordedAuthDB

func (db *Database) RecordedAuthDB(t *testing.T) (*authdb.Client, *QueryRecorder)

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

type QueryRecorder struct {
	types.DBTX
	// contains filtered or unexported fields
}

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) Query

func (r *QueryRecorder) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*QueryRecorder) QueryRow

func (r *QueryRecorder) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

func (*QueryRecorder) Take

func (r *QueryRecorder) Take() []string

Take returns the names recorded since the last call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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