Documentation
¶
Overview ¶
Package testutil provides shared test utilities for Melange integration tests.
Package testutil provides shared test utilities for Melange integration tests.
Package testutil provides shared test utilities for Melange integration tests.
Index ¶
- func DB(tb testing.TB) *sql.DB
- func DBWithDatabaseSchema(tb testing.TB, databaseSchema string) *sql.DB
- func DSN(tb testing.TB) string
- func DSNWithDatabaseSchema(tb testing.TB, databaseSchema string) string
- func DomainTablesSQL() string
- func EmptyDB(tb testing.TB) *sql.DB
- func PostgresSchema(schema string) string
- func TuplesViewSQL(databaseSchema string) string
- type BulkFixtures
- func (bf *BulkFixtures) AddOrganizationMembers(orgID int64, userIDs []int64, role string) error
- func (bf *BulkFixtures) CreateOrganizations(n int) ([]int64, error)
- func (bf *BulkFixtures) CreatePullRequests(repoID int64, authorIDs []int64, n int) ([]int64, error)
- func (bf *BulkFixtures) CreateRepositories(orgID int64, n int) ([]int64, error)
- func (bf *BulkFixtures) CreateUsers(n int) ([]int64, error)
- func (bf *BulkFixtures) TupleCount() (int, error)
- type DatabaseConfig
- type Fixtures
- func (f *Fixtures) AddOrganizationMembers(orgID int64, userIDs []int64, role string) error
- func (f *Fixtures) CreateOrganizations(n int) ([]int64, error)
- func (f *Fixtures) CreatePullRequests(repoID int64, authorIDs []int64, n int) ([]int64, error)
- func (f *Fixtures) CreateRepositories(orgID int64, n int) ([]int64, error)
- func (f *Fixtures) CreateUsers(n int) ([]int64, error)
- func (f *Fixtures) TupleCount() (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DB ¶
DB returns a fully migrated database connection for testing. Each call creates a new isolated database copied from the template. The database is automatically cleaned up when the test completes. Works with both *testing.T and *testing.B.
If DATABASE_URL environment variable is set, connects to remote database instead.
func DBWithDatabaseSchema ¶ added in v0.8.0
func DSN ¶ added in v0.7.0
DSN returns the connection string for an isolated test database. Unlike DB(), it returns the raw DSN so callers can open with any driver. The database is automatically cleaned up when the test completes.
func DSNWithDatabaseSchema ¶ added in v0.8.0
func DomainTablesSQL ¶
func DomainTablesSQL() string
DomainTablesSQL returns the embedded SQL for creating domain tables. Domain tables always live in the public schema.
func EmptyDB ¶
EmptyDB returns an empty database connection for testing. Each call creates a new isolated empty database. The database is automatically cleaned up when the test completes. Works with both *testing.T and *testing.B.
func PostgresSchema ¶ added in v0.8.0
PostgresSchema returns a literal with the schema name or "current_schema()" if empty.
func TuplesViewSQL ¶
TuplesViewSQL returns the embedded SQL for creating the tuples view.
Types ¶
type BulkFixtures ¶ added in v0.6.0
type BulkFixtures struct {
// contains filtered or unexported fields
}
BulkFixtures provides factory functions for creating test data using PostgreSQL COPY FROM. This is 10-100x faster than batch INSERTs for large datasets.
func NewBulkFixtures ¶ added in v0.6.0
func NewBulkFixtures(ctx context.Context, db *sql.DB) *BulkFixtures
NewBulkFixtures creates a new BulkFixtures instance for bulk data loading via COPY FROM.
func (*BulkFixtures) AddOrganizationMembers ¶ added in v0.6.0
func (bf *BulkFixtures) AddOrganizationMembers(orgID int64, userIDs []int64, role string) error
AddOrganizationMembers adds users to an organization with the specified role using COPY FROM.
func (*BulkFixtures) CreateOrganizations ¶ added in v0.6.0
func (bf *BulkFixtures) CreateOrganizations(n int) ([]int64, error)
CreateOrganizations creates n organizations using COPY FROM. Falls back to batch INSERT if COPY fails.
func (*BulkFixtures) CreatePullRequests ¶ added in v0.6.0
CreatePullRequests creates pull requests in the given repository using COPY FROM. Cycles through authorIDs for each PR.
func (*BulkFixtures) CreateRepositories ¶ added in v0.6.0
func (bf *BulkFixtures) CreateRepositories(orgID int64, n int) ([]int64, error)
CreateRepositories creates n repositories under an organization using COPY FROM.
func (*BulkFixtures) CreateUsers ¶ added in v0.6.0
func (bf *BulkFixtures) CreateUsers(n int) ([]int64, error)
CreateUsers creates n users using COPY FROM for bulk loading. Falls back to batch INSERT if COPY fails.
func (*BulkFixtures) TupleCount ¶ added in v0.6.0
func (bf *BulkFixtures) TupleCount() (int, error)
TupleCount returns the current count of tuples in the melange_tuples view.
type DatabaseConfig ¶ added in v0.6.0
DatabaseConfig holds configuration for connecting to a database.
func GetDatabaseConfig ¶ added in v0.6.0
func GetDatabaseConfig() DatabaseConfig
GetDatabaseConfig reads database configuration from environment variables. If DATABASE_URL is set, it returns configuration for a remote database. Otherwise, returns an empty config which signals to use testcontainers.
type Fixtures ¶
type Fixtures struct {
// contains filtered or unexported fields
}
Fixtures provides factory functions for creating test data in bulk. All functions use batch inserts for efficiency at scale.
func NewFixtures ¶
NewFixtures creates a new Fixtures instance for bulk data insertion.
func (*Fixtures) AddOrganizationMembers ¶
AddOrganizationMembers adds users to an organization with the specified role. role must be one of: owner, admin, member, billing_manager
func (*Fixtures) CreateOrganizations ¶
CreateOrganizations creates n organizations and returns their IDs.
func (*Fixtures) CreatePullRequests ¶
CreatePullRequests creates pull requests in the given repository. Cycles through authorIDs for each PR.
func (*Fixtures) CreateRepositories ¶
CreateRepositories creates n repositories under an organization and returns their IDs.
func (*Fixtures) CreateUsers ¶
CreateUsers creates n users and returns their IDs.
func (*Fixtures) TupleCount ¶
TupleCount returns the current count of tuples in the melange_tuples view.