tests

package
v0.19.986 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: AGPL-3.0 Imports: 63 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearQueueSignals added in v0.19.986

func ClearQueueSignals(t testing.TB, db *gorm.DB)

ClearQueueSignals deletes all queue signals from the DB.

func CreateAndMigrateCHDatabase added in v0.19.821

func CreateAndMigrateCHDatabase(chCfg CHConfig) error

CreateAndMigrateCHDatabase drops and recreates the ClickHouse test database, then runs migrations. Called by the testsetup binary before tests run.

func CreateAndMigrateDatabase added in v0.19.821

func CreateAndMigrateDatabase(cfg DBConfig) error

CreateAndMigrateDatabase drops and recreates the test database, then runs migrations. Called by the testsetup binary before tests run.

func CtlApiFXOptions

func CtlApiFXOptions(t testing.TB) []fx.Option

CtlApiFXOptions returns the common FX options used across all ctl-api integration tests. For tests that need mocks, use CtlApiFXOptionsWithMocks instead.

func CtlApiFXOptionsWithMocks added in v0.19.807

func CtlApiFXOptionsWithMocks(opts TestOpts) []fx.Option

CtlApiFXOptionsWithMocks returns FX options for integration tests with configurable mock clients and validator choice.

Usage:

opts := tests.CtlApiFXOptionsWithMocks(tests.TestOpts{
    CustomValidator: true,
})
app := fxtest.New(t, append(opts, fx.Provide(MyService), fx.Populate(&svc))...)

func CtlApiFXOptionsWithValidator deprecated

func CtlApiFXOptionsWithValidator(t testing.TB) []fx.Option

CtlApiFXOptionsWithValidator returns common test options with the standard validator.

Deprecated: Use CtlApiFXOptionsWithMocks(tests.TestOpts{}) instead.

func GetQueueSignals added in v0.19.986

func GetQueueSignals(t testing.TB, db *gorm.DB) []app.QueueSignal

GetQueueSignals returns all queue signals from the DB, ordered by creation time.

func GetQueueSignalsByOwner added in v0.19.986

func GetQueueSignalsByOwner(t testing.TB, db *gorm.DB, ownerID string) []app.QueueSignal

GetQueueSignalsByOwner returns queue signals for a specific owner.

func MigrateTestCHDatabase added in v0.19.821

func MigrateTestCHDatabase(chCfg CHConfig) error

MigrateTestCHDatabase connects to the ClickHouse test database and runs migrations. CH migration state is tracked in PostgreSQL, so we need both connections.

func MigrateTestDatabase added in v0.19.821

func MigrateTestDatabase(cfg DBConfig) error

MigrateTestDatabase connects to the test database and runs all migrations.

func NewTestRouter

func NewTestRouter(opts RouterOptions) *gin.Engine

NewTestRouter creates a gin router with standard test middlewares.

Standard middlewares included (in order): 1. stderr - Error handling and JSON error responses (REQUIRED) 2. patcher - PATCH request field extraction for partial updates 3. pagination - Query parameter parsing for paginated endpoints 4. context injection - Injects test org and account into context

Usage:

router := testfx.NewTestRouter(testfx.RouterOptions{
    L:       s.service.L,
    DB:      s.service.DB,
    TestOrg: s.testOrg,
    TestAcc: s.testAcc,
})

With additional middlewares:

router := testfx.NewTestRouter(testfx.RouterOptions{
    L:       s.service.L,
    DB:      s.service.DB,
    TestOrg: s.testOrg,
    TestAcc: s.testAcc,
    AdditionalMiddlewares: []gin.HandlerFunc{
        myCustomMiddleware.Handler(),
    },
})

func NopFxLogger added in v0.19.807

func NopFxLogger() fxevent.Logger

func SkipIfNotIntegration

func SkipIfNotIntegration(t *testing.T)

SkipIfNotIntegration skips the test if INTEGRATION != "true". Call this at the start of TestXxxSuite functions.

Types

type BaseDBTestSuite

type BaseDBTestSuite struct {
	suite.Suite
	// contains filtered or unexported fields
}

BaseDBTestSuite provides the base test suite for database-backed tests. Embed this in your test suites. The database must already exist and be migrated (via the testsetup binary) before tests run.

Tests rely on unique names for data isolation — no truncation is needed.

Example:

type MyTestSuite struct {
    tests.BaseDBTestSuite
    // your fields
}

func TestMySuite(t *testing.T) {
    tests.SkipIfNotIntegration(t)
    suite.Run(t, new(MyTestSuite))
}

func (s *MyTestSuite) SetupSuite() {
    s.BaseDBTestSuite.SetupSuite()
    // create your fx app and get DB
    s.SetDB(db)
    s.SetCHDB(chDB) // optional
}

func (*BaseDBTestSuite) CHDB added in v0.19.807

func (s *BaseDBTestSuite) CHDB() *gorm.DB

CHDB returns the ClickHouse database connection.

func (*BaseDBTestSuite) DB

func (s *BaseDBTestSuite) DB() *gorm.DB

DB returns the PostgreSQL database connection.

func (*BaseDBTestSuite) SetCHDB added in v0.19.807

func (s *BaseDBTestSuite) SetCHDB(db *gorm.DB)

SetCHDB stores the ClickHouse database connection.

func (*BaseDBTestSuite) SetDB

func (s *BaseDBTestSuite) SetDB(db *gorm.DB)

SetDB stores the PostgreSQL database connection.

func (*BaseDBTestSuite) SetupSuite

func (s *BaseDBTestSuite) SetupSuite()

SetupSuite is a no-op. The database is created by the testsetup binary before tests run.

func (*BaseDBTestSuite) SetupTest

func (s *BaseDBTestSuite) SetupTest()

SetupTest is a no-op. Tests use unique names for data isolation.

type CHConfig added in v0.19.821

type CHConfig struct {
	Host     string `config:"clickhouse_db_host"`
	Port     string `config:"clickhouse_db_port"`
	User     string `config:"clickhouse_db_user"`
	Password string `config:"clickhouse_db_password"`
	Name     string `config:"clickhouse_db_name"`
	UseTLS   bool   `config:"clickhouse_db_use_tls"`

	ReadTimeout  time.Duration `config:"clickhouse_db_read_timeout"`
	WriteTimeout time.Duration `config:"clickhouse_db_write_timeout"`
	DialTimeout  time.Duration `config:"clickhouse_db_dial_timeout"`
}

CHConfig holds the ClickHouse connection fields. Uses the same config tags as internal.Config so it picks up the registered defaults.

func LoadCHConfig added in v0.19.821

func LoadCHConfig() (CHConfig, error)

LoadCHConfig loads the ClickHouse config from environment variables.

type DBConfig added in v0.19.821

type DBConfig struct {
	DBHost     string `config:"db_host"`
	DBPort     string `config:"db_port"`
	DBUser     string `config:"db_user"`
	DBPassword string `config:"db_password"`
	DBSSLMode  string `config:"db_ssl_mode"`
	DBName     string `config:"db_name"`
}

DBConfig holds just the database connection fields we need. Uses the same config tags as internal.Config so it picks up the registered defaults.

func LoadDBConfig added in v0.19.821

func LoadDBConfig() (DBConfig, error)

LoadDBConfig loads the database config from environment variables.

type RouterOptions

type RouterOptions struct {
	// Logger for middlewares
	L *zap.Logger
	// Database for pagination and patcher middleware
	DB *gorm.DB
	// TestOrg to inject into context (optional)
	TestOrg *app.Org
	// TestAccount to inject into context (optional)
	TestAcc *app.Account
	// AdditionalMiddlewares to add after standard middlewares (optional)
	AdditionalMiddlewares []gin.HandlerFunc
}

RouterOptions configures the test router setup.

type TestMocks added in v0.19.807

type TestMocks struct {
	MockTC temporalclient.Client
	MockGH vcshelpers.GithubClient
	MockTF terraform.Client
}

TestMocks holds optional mock/fake clients that tests can supply to CtlApiFXOptionsWithMocks. Tests create their own mock instances and pass them in; FX registers them as the interface types.

type TestOpts added in v0.19.807

type TestOpts struct {
	// T is required for creating default gomock-based mock clients.
	T testing.TB
	// Mocks to inject. Nil fields use default mocks.
	Mocks *TestMocks
	// CustomValidator uses the custom entity_name validator when true,
	// standard validator when false.
	CustomValidator bool
}

TestOpts configures the FX options for integration tests.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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