diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-13 21:43:11 -0800 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-13 21:43:11 -0800 |
| commit | 28dd0bfc1373746b8c056a211f068da71fdc80b2 (patch) | |
| tree | 9c04a08501bc5abe7413263f60eaa55400dd162f /internal/services/migration_executor_test.go | |
| parent | Release v0.13.1 (diff) | |
| download | cli-28dd0bfc1373746b8c056a211f068da71fdc80b2.zip | |
Remove migration dependencies
Diffstat (limited to 'internal/services/migration_executor_test.go')
| -rw-r--r-- | internal/services/migration_executor_test.go | 230 |
1 files changed, 0 insertions, 230 deletions
diff --git a/internal/services/migration_executor_test.go b/internal/services/migration_executor_test.go deleted file mode 100644 index 00e7402..0000000 --- a/internal/services/migration_executor_test.go +++ /dev/null @@ -1,230 +0,0 @@ -package services - -import ( - "errors" - "testing" - - "git.sr.ht/~eugenetriguba/bolt/internal/bolttest" - "git.sr.ht/~eugenetriguba/bolt/internal/models" - "git.sr.ht/~eugenetriguba/bolt/internal/sqlparse" - "git.sr.ht/~eugenetriguba/checkmate/assert" -) - -func TestExecutorApply_WithTransaction(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadUpgradeScriptReturnValue: bolttest.ReadUpgradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Contents: "CREATE TABLE tmp(id INT PRIMARY KEY);", - Options: sqlparse.ExecutionOptions{UseTransaction: true}, - }, - Err: nil, - }, - } - - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - ApplyWithTxReturnValue: bolttest.ApplyWithTxReturnValue{ - Err: nil, - }, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Apply(&models.Migration{}) - - assert.Nil(t, err) - assert.Equal(t, migrationDbRepo.ApplyWithTxCallCount, 1) - assert.Equal(t, migrationDbRepo.ApplyCallCount, 0) -} - -func TestExecutorApply_WithoutTransaction(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadUpgradeScriptReturnValue: bolttest.ReadUpgradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Contents: "CREATE TABLE tmp(id INT PRIMARY KEY);", - Options: sqlparse.ExecutionOptions{UseTransaction: false}, - }, - Err: nil, - }, - } - - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - ApplyReturnValue: bolttest.ApplyReturnValue{ - Err: nil, - }, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Apply(&models.Migration{}) - - assert.Nil(t, err) - assert.Equal(t, migrationDbRepo.ApplyWithTxCallCount, 0) - assert.Equal(t, migrationDbRepo.ApplyCallCount, 1) -} - -func TestExecutorApply_ReadUpgradeScriptErr(t *testing.T) { - expectedErr := errors.New("error!") - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadUpgradeScriptReturnValue: bolttest.ReadUpgradeScriptReturnValue{ - Script: sqlparse.MigrationScript{}, - Err: expectedErr, - }, - } - - migrationDbRepo := &bolttest.MockMigrationDBRepo{} - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Apply(&models.Migration{}) - - assert.ErrorIs(t, err, expectedErr) -} - -func TestExecutorApply_ApplyWithTxErr(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadUpgradeScriptReturnValue: bolttest.ReadUpgradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Options: sqlparse.ExecutionOptions{ - UseTransaction: true, - }, - }, - Err: nil, - }, - } - expectedErr := errors.New("error!") - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - ApplyWithTxReturnValue: bolttest.ApplyWithTxReturnValue{Err: expectedErr}, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Apply(&models.Migration{}) - - assert.ErrorIs(t, err, expectedErr) -} - -func TestExecutorApply_ApplyErr(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadUpgradeScriptReturnValue: bolttest.ReadUpgradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Options: sqlparse.ExecutionOptions{ - UseTransaction: false, - }, - }, - Err: nil, - }, - } - expectedErr := errors.New("error!") - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - ApplyReturnValue: bolttest.ApplyReturnValue{Err: expectedErr}, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Apply(&models.Migration{}) - - assert.ErrorIs(t, err, expectedErr) -} - -func TestExecutorRevert_WithTransaction(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadDowngradeScriptReturnValue: bolttest.ReadDowngradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Contents: "DROP TABLE tmp;", - Options: sqlparse.ExecutionOptions{UseTransaction: true}, - }, - Err: nil, - }, - } - - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - RevertWithTxReturnValue: bolttest.RevertWithTxReturnValue{ - Err: nil, - }, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Revert(&models.Migration{}) - - assert.Nil(t, err) - assert.Equal(t, migrationDbRepo.RevertWithTxCallCount, 1) - assert.Equal(t, migrationDbRepo.RevertCallCount, 0) -} - -func TestExecutorRevert_WithoutTransaction(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadDowngradeScriptReturnValue: bolttest.ReadDowngradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Contents: "DROP TABLE tmp;", - Options: sqlparse.ExecutionOptions{UseTransaction: false}, - }, - Err: nil, - }, - } - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - RevertReturnValue: bolttest.RevertReturnValue{ - Err: nil, - }, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Revert(&models.Migration{}) - - assert.Nil(t, err) - assert.Equal(t, migrationDbRepo.RevertWithTxCallCount, 0) - assert.Equal(t, migrationDbRepo.RevertCallCount, 1) -} - -func TestExecutorRevert_ReadDowngradeScriptErr(t *testing.T) { - expectedErr := errors.New("error!") - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadDowngradeScriptReturnValue: bolttest.ReadDowngradeScriptReturnValue{ - Script: sqlparse.MigrationScript{}, - Err: expectedErr, - }, - } - migrationDbRepo := &bolttest.MockMigrationDBRepo{} - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Revert(&models.Migration{}) - - assert.ErrorIs(t, err, expectedErr) -} - -func TestExecutorRevert_RevertWithTxErr(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadDowngradeScriptReturnValue: bolttest.ReadDowngradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Options: sqlparse.ExecutionOptions{ - UseTransaction: true, - }, - }, - Err: nil, - }, - } - expectedErr := errors.New("error!") - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - RevertWithTxReturnValue: bolttest.RevertWithTxReturnValue{Err: expectedErr}, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Revert(&models.Migration{}) - - assert.ErrorIs(t, err, expectedErr) -} - -func TestExecutorRevert_RevertErr(t *testing.T) { - migrationFsRepo := &bolttest.MockMigrationFsRepo{ - ReadDowngradeScriptReturnValue: bolttest.ReadDowngradeScriptReturnValue{ - Script: sqlparse.MigrationScript{ - Options: sqlparse.ExecutionOptions{ - UseTransaction: false, - }, - }, - Err: nil, - }, - } - expectedErr := errors.New("error!") - migrationDbRepo := &bolttest.MockMigrationDBRepo{ - RevertReturnValue: bolttest.RevertReturnValue{Err: expectedErr}, - } - - executor := NewMigrationExecutor(migrationDbRepo, migrationFsRepo) - err := executor.Revert(&models.Migration{}) - - assert.ErrorIs(t, err, expectedErr) -} |