Documentation
¶
Index ¶
- func CreateTestClickHouseDatabase() error
- func CreateTestDatabase() error
- func CtlApiFXOptions(t testing.TB) []fx.Option
- func CtlApiFXOptionsWithMocks(opts TestOpts) []fx.Option
- func CtlApiFXOptionsWithValidator(t testing.TB) []fx.Optiondeprecated
- func NewTestRouter(opts RouterOptions) *gin.Engine
- func NopFxLogger() fxevent.Logger
- func SkipIfNotIntegration(t *testing.T)
- func TruncateAllCHTables(ctx context.Context, db *gorm.DB) error
- func TruncateAllTables(ctx context.Context, db *gorm.DB) error
- type BaseDBTestSuite
- type CapturedSignal
- 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 CreateTestClickHouseDatabase ¶ added in v0.19.807
func CreateTestClickHouseDatabase() error
CreateTestClickHouseDatabase creates the ClickHouse test database if it doesn't exist and runs migrations. Uses the same config system as the service to get connection parameters.
func CreateTestDatabase ¶
func CreateTestDatabase() error
CreateTestDatabase creates the test database if it doesn't exist and runs migrations. Uses the same config system as the service to get connection parameters. The DB_NAME environment variable must be set (e.g. via nuonctl-test-env.yml).
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 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.
func TruncateAllCHTables ¶ added in v0.19.807
TruncateAllCHTables truncates all ClickHouse tables.
Types ¶
type BaseDBTestSuite ¶
BaseDBTestSuite provides automatic test database setup and truncation. Embed this in your test suites and call SetDB() in SetupSuite after creating your DB connection. Optionally call SetCHDB() to enable ClickHouse table truncation between tests.
Example:
type MyTestSuite struct {
testdb.BaseDBTestSuite
// your fields
}
func TestMySuite(t *testing.T) {
testdb.SkipIfNotIntegration(t)
suite.Run(t, new(MyTestSuite))
}
func (s *MyTestSuite) SetupSuite() {
s.BaseDBTestSuite.SetupSuite() // creates test DB and sets env
// create your fx app and get DB
s.SetDB(db)
s.SetCHDB(chDB) // optional: enable CH truncation
}
Tables are automatically truncated before each test via SetupTest.
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 for use in truncation. Call this in your SetupSuite after creating the CH connection. If not called, ClickHouse tables will not be truncated between tests.
func (*BaseDBTestSuite) SetDB ¶
func (s *BaseDBTestSuite) SetDB(db *gorm.DB)
SetDB stores the PostgreSQL database connection for use in truncation. Call this in your SetupSuite after creating the DB connection.
func (*BaseDBTestSuite) SetupSuite ¶
func (s *BaseDBTestSuite) SetupSuite()
SetupSuite creates the test databases if needed. Call this at the start of your SetupSuite if you override it. DB_NAME and CLICKHOUSE_DB_NAME must already be set in the environment.
func (*BaseDBTestSuite) SetupTest ¶
func (s *BaseDBTestSuite) SetupTest()
SetupTest truncates all tables before each test. If you override SetupTest in your suite, call s.BaseDBTestSuite.SetupTest() first.
type CapturedSignal ¶ added in v0.19.770
CapturedSignal holds information about a signal that was sent.
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
}
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.