Documentation ¶
Index ¶
- func EnableDBRecordMode() suitetest.PackageOptions
- func IsRecording() bool
- func PrepareData(di *DI, steps ...DataSetupStep) test.SetupFunc
- func PrepareDataWithScope(di *DI, scope DataSetupScope, steps ...DataSetupStep) test.SetupFunc
- func WithDBPlayback(dbName string, opts ...DBOptions) test.Options
- func WithNoopMocks() test.Options
- type DBOption
- type DBOptions
- type DI
- type DataSetupScope
- type DataSetupStep
- func SetupDropTables(tables ...string) DataSetupStep
- func SetupOnce(once *sync.Once, steps ...DataSetupStep) DataSetupStep
- func SetupTruncateTables(tables ...string) DataSetupStep
- func SetupUsingModelSeedFile(fsys fs.FS, dest interface{}, filename string, ...) DataSetupStep
- func SetupUsingSQLFile(fsys fs.FS, filenames ...string) DataSetupStep
- func SetupUsingSQLQueries(queries ...string) DataSetupStep
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnableDBRecordMode ¶
func EnableDBRecordMode() suitetest.PackageOptions
EnableDBRecordMode Force enables DB recording mode. Normally recording mode should be enabled via `go test` argument `-record` IMPORTANT: when Record mode is enabled, all tests executing SQL against actual database. Or if Opensearch is being used, any queries to that will be executed against the real opensearch service.
So use this mode on LOCAL DEV ONLY, and have the DB copied before executing
func PrepareData ¶
func PrepareData(di *DI, steps ...DataSetupStep) test.SetupFunc
PrepareData is a convenient function that returns a test.SetupFunc that executes given DataSetupStep in provided order Note: PrepareData accumulate all changes applied to context
func PrepareDataWithScope ¶
func PrepareDataWithScope(di *DI, scope DataSetupScope, steps ...DataSetupStep) test.SetupFunc
PrepareDataWithScope is similar to PrepareData, it applies given DataSetupScope before executing all DataSetupStep. DataSetupScope is used to prepare context and gorm.DB for all given DataSetupStep Note: Different from PrepareData, PrepareDataWithScope doesn't accumulate changes to context
func WithDBPlayback ¶
WithDBPlayback enables DB SQL playback capabilities supported by `copyist` This mode requires apptest.Bootstrap to work, and should not be used together with WithNoopMocks Each top-level test should have corresponding recorded SQL responses in `testdata` folder, or the test will fail. To enable record mode, use `go test ... -record` at CLI, or do it programmatically with EnableDBRecordMode See https://github.com/cockroachdb/copyist for more details
func WithNoopMocks ¶
WithNoopMocks create a noop tx.TxManager and a noop gorm.DB This mode requires apptest.Bootstrap to work, and should not be used together with WithDBPlayback Note: in this mode, gorm.DB's DryRun and SkipDefaultTransaction are enabled
Types ¶
type DataSetupScope ¶
type DataSetupScope func(ctx context.Context, t *testing.T, db *gorm.DB) (context.Context, *gorm.DB)
func SetupWithGormScopes ¶
func SetupWithGormScopes(scopes ...func(*gorm.DB) *gorm.DB) DataSetupScope
SetupWithGormScopes returns a DataSetupScope that applies given gorm scopes
type DataSetupStep ¶
func SetupDropTables ¶
func SetupDropTables(tables ...string) DataSetupStep
SetupDropTables returns a DataSetupStep that truncate given tables in single DROP TABLE IF EXISTS
func SetupOnce ¶
func SetupOnce(once *sync.Once, steps ...DataSetupStep) DataSetupStep
SetupOnce returns a DataSetupStep that run given DataSetupSteps within the given sync.Once. How sync.Once is scoped is up to caller. e.g. once per test, once per package execution, etc...
func SetupTruncateTables ¶
func SetupTruncateTables(tables ...string) DataSetupStep
SetupTruncateTables returns a DataSetupStep that truncate given tables in the provided order
func SetupUsingModelSeedFile ¶
func SetupUsingModelSeedFile(fsys fs.FS, dest interface{}, filename string, closures ...func(ctx context.Context, db *gorm.DB)) DataSetupStep
SetupUsingModelSeedFile returns a DataSetupStep that load provided yaml file and parse it directly into provided model and save them. when "closures" is provided, it's invoked after seeding is done.
func SetupUsingSQLFile ¶
func SetupUsingSQLFile(fsys fs.FS, filenames ...string) DataSetupStep
SetupUsingSQLFile returns a DataSetupStep that execute the provided sql file in given FS.
func SetupUsingSQLQueries ¶
func SetupUsingSQLQueries(queries ...string) DataSetupStep
SetupUsingSQLQueries returns a DataSetupStep that execute the provided sql queries.