From ca606d508b6b9592841e08b19175775146e42e3e Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 18 Aug 2024 18:55:12 -0400 Subject: Add a few more tests to the migration service --- internal/services/migration_test.go | 108 ++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'internal/services/migration_test.go') diff --git a/internal/services/migration_test.go b/internal/services/migration_test.go index 6828d28..1cfc3ba 100644 --- a/internal/services/migration_test.go +++ b/internal/services/migration_test.go @@ -662,6 +662,60 @@ func TestApplyMigration_ReadUpgradeScriptErr(t *testing.T) { assert.ErrorIs(t, err, expectedErr) } +func TestApplyMigration_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}, + } + svc := NewMigrationService( + migrationDbRepo, + migrationFsRepo, + configloader.Config{}, + bolttest.NullOutputter{}, + ) + + err := svc.ApplyMigration(&models.Migration{}) + + assert.ErrorIs(t, err, expectedErr) +} + +func TestApplyMigration_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}, + } + svc := NewMigrationService( + migrationDbRepo, + migrationFsRepo, + configloader.Config{}, + bolttest.NullOutputter{}, + ) + + err := svc.ApplyMigration(&models.Migration{}) + + assert.ErrorIs(t, err, expectedErr) +} + func TestApplyAllMigrations_ListMigrationsErr(t *testing.T) { expectedErr := errors.New("error!") migrationFsRepo := &bolttest.MockMigrationFsRepo{ @@ -944,6 +998,60 @@ func TestRevertMigration_ReadUpgradeScriptErr(t *testing.T) { assert.ErrorIs(t, err, expectedErr) } +func TestRevertMigration_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}, + } + svc := NewMigrationService( + migrationDbRepo, + migrationFsRepo, + configloader.Config{}, + bolttest.NullOutputter{}, + ) + + err := svc.RevertMigration(&models.Migration{}) + + assert.ErrorIs(t, err, expectedErr) +} + +func TestRevertMigration_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}, + } + svc := NewMigrationService( + migrationDbRepo, + migrationFsRepo, + configloader.Config{}, + bolttest.NullOutputter{}, + ) + + err := svc.RevertMigration(&models.Migration{}) + + assert.ErrorIs(t, err, expectedErr) +} + func TestRevertDownToVersion_ListMigrationsErr(t *testing.T) { expectedErr := errors.New("error!") migrationFsRepo := &bolttest.MockMigrationFsRepo{ -- cgit v1.2.3