Documentation
¶
Index ¶
- func CreateAndMigrateCHDatabase(chCfg CHConfig) 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 MigrateTestCHDatabase(chCfg CHConfig) error
- func MigrateTestDatabase(cfg DBConfig) error
- func NewTestRouter(opts RouterOptions) *gin.Engine
- func NopFxLogger() fxevent.Logger
- func SkipIfNotIntegration(t *testing.T)
- type BaseDBTestSuite
- type CHConfig
- type CapturedSignal
- type DBConfig
- type FakeEventLoopClient
- func (f *FakeEventLoopClient) Cancel(ctx context.Context, namespace, id string) error
- func (f *FakeEventLoopClient) GetSignals() []CapturedSignal
- func (f *FakeEventLoopClient) GetWorkflowCount(ctx context.Context, namespace string, workflowID string) (int64, error)
- func (f *FakeEventLoopClient) GetWorkflowStatus(ctx context.Context, namespace string, workflowID string) (enumsv1.WorkflowExecutionStatus, error)
- func (f *FakeEventLoopClient) Reset()
- func (f *FakeEventLoopClient) Send(ctx context.Context, id string, signal eventloop.Signal)
- type MockEventLoopClient
- type RouterOptions
- type TestMocks
- type TestOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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:
mockEv := tests.NewMockEventLoopClient()
opts := tests.CtlApiFXOptionsWithMocks(tests.TestOpts{
Mocks: &tests.TestMocks{MockEv: mockEv},
CustomValidator: true,
})
app := fxtest.New(t, append(opts, fx.Provide(MyService), fx.Populate(&svc))...)
func CtlApiFXOptionsWithValidator
deprecated
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.
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 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 CapturedSignal ¶ added in v0.19.770
CapturedSignal holds information about a signal that was sent.
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 FakeEventLoopClient ¶ added in v0.19.770
type FakeEventLoopClient struct {
// contains filtered or unexported fields
}
FakeEventLoopClient is a test implementation of eventloop.Client that records signals.
func NewFakeEventLoopClient ¶ added in v0.19.770
func NewFakeEventLoopClient() *FakeEventLoopClient
NewFakeEventLoopClient creates a new fake event loop client for testing.
func NewMockEventLoopClient ¶ added in v0.19.807
func NewMockEventLoopClient() *FakeEventLoopClient
NewMockEventLoopClient is an alias for NewFakeEventLoopClient for backward compatibility.
func (*FakeEventLoopClient) Cancel ¶ added in v0.19.770
func (f *FakeEventLoopClient) Cancel(ctx context.Context, namespace, id string) error
Cancel implements eventloop.Client (no-op for testing).
func (*FakeEventLoopClient) GetSignals ¶ added in v0.19.770
func (f *FakeEventLoopClient) GetSignals() []CapturedSignal
GetSignals returns all captured signals.
func (*FakeEventLoopClient) GetWorkflowCount ¶ added in v0.19.770
func (f *FakeEventLoopClient) GetWorkflowCount(ctx context.Context, namespace string, workflowID string) (int64, error)
GetWorkflowCount implements eventloop.Client (returns 1 for testing).
func (*FakeEventLoopClient) GetWorkflowStatus ¶ added in v0.19.770
func (f *FakeEventLoopClient) GetWorkflowStatus(ctx context.Context, namespace string, workflowID string) (enumsv1.WorkflowExecutionStatus, error)
GetWorkflowStatus implements eventloop.Client (returns completed for testing).
func (*FakeEventLoopClient) Reset ¶ added in v0.19.770
func (f *FakeEventLoopClient) Reset()
Reset clears all captured signals.
type MockEventLoopClient ¶ added in v0.19.807
type MockEventLoopClient = FakeEventLoopClient
MockEventLoopClient is an alias for FakeEventLoopClient for backward compatibility.
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 {
MockEv eventloop.Client
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.