Documentation
¶
Index ¶
- func ClearQueueSignals(t testing.TB, db *gorm.DB)
- func CreateAndMigrateCHDatabase(chCfg CHConfig, psqlCfg DBConfig) error
- func CreateAndMigrateDatabase(cfg DBConfig) error
- func CtlApiFXOptions(t testing.TB) []fx.Option
- func CtlApiFXOptionsWithMocks(opts TestOpts) []fx.Option
- func CtlApiFXOptionsWithValidator(t testing.TB) []fx.Optiondeprecated
- func DumpSchema(cfg DBConfig, dir string) error
- func GetQueueSignals(t testing.TB, db *gorm.DB) []app.QueueSignal
- func GetQueueSignalsByOwner(t testing.TB, db *gorm.DB, ownerID string) []app.QueueSignal
- func MigrateTestCHDatabase(chCfg CHConfig, psqlCfg DBConfig) error
- func MigrateTestDatabase(cfg DBConfig) error
- func NewTestRouter(opts RouterOptions) *gin.Engine
- func NopFxLogger() fxevent.Logger
- func ResetDatabase(cfg DBConfig) error
- func RestoreDatabase(cfg DBConfig, snapshotPath string) error
- func SchemaSnapshotDir() string
- func SchemaSnapshotPath(cfg DBConfig) (string, bool)
- func SkipIfNotIntegration(t *testing.T)
- type BaseDBTestSuite
- type CHConfig
- type DBConfig
- type RouterOptions
- type TestMocks
- type TestOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearQueueSignals ¶ added in v0.19.986
ClearQueueSignals deletes all queue signals from the DB.
func CreateAndMigrateCHDatabase ¶ added in v0.19.821
CreateAndMigrateCHDatabase drops and recreates the ClickHouse test database, then runs migrations. Called by the testsetup binary before tests run. CH migration state is tracked in PostgreSQL, so psqlCfg must be the config of the Postgres database paired with this ClickHouse database — it is the migration ledger.
func CreateAndMigrateDatabase ¶ added in v0.19.821
CreateAndMigrateDatabase drops and recreates the test database, then runs migrations. Called by the testsetup binary before tests run.
func CtlApiFXOptions ¶
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
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 DumpSchema ¶ added in v0.19.1172
DumpSchema writes a pg_dump of the migrated database into dir. The CI lane snapshots the freshly migrated schema so later runs restore it instead of replaying migrations; written atomically so a concurrent cache save never sees a partial file.
func GetQueueSignals ¶ added in v0.19.986
GetQueueSignals returns all queue signals from the DB, ordered by creation time.
func GetQueueSignalsByOwner ¶ added in v0.19.986
GetQueueSignalsByOwner returns queue signals for a specific owner.
func MigrateTestCHDatabase ¶ added in v0.19.821
MigrateTestCHDatabase connects to the ClickHouse test database and runs migrations. CH migration state is tracked in PostgreSQL, so we need both connections. psqlCfg must be the Postgres database paired with this ClickHouse database.
func MigrateTestDatabase ¶ added in v0.19.821
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 ResetDatabase ¶ added in v0.19.1172
ResetDatabase terminates connections, drops, and recreates the test database without running migrations.
func RestoreDatabase ¶ added in v0.19.1172
RestoreDatabase recreates the test database from a pg_dump snapshot, skipping migrations.
func SchemaSnapshotDir ¶ added in v0.19.1172
func SchemaSnapshotDir() string
SchemaSnapshotDir names the directory NUONTEST_PG_SCHEMA_DIR uses to pass pre-migrated pg_dump snapshots between CI runs.
func SchemaSnapshotPath ¶ added in v0.19.1172
SchemaSnapshotPath returns the snapshot file for the database and whether it exists.
func SkipIfNotIntegration ¶
SkipIfNotIntegration skips the test if INTEGRATION != "true". Call this at the start of TestXxxSuite functions.
Types ¶
type BaseDBTestSuite ¶
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
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
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.