aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-08-18 18:55:12 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2024-08-18 18:55:12 -0400
commitca606d508b6b9592841e08b19175775146e42e3e (patch)
tree814c421389e22ccdea68ea27b0a8be941fa4c140 /internal
parentAdd test around schema scenario with mssql (diff)
downloadcli-ca606d508b6b9592841e08b19175775146e42e3e.zip
Add a few more tests to the migration service
Diffstat (limited to 'internal')
-rw-r--r--internal/services/migration_test.go108
1 files changed, 108 insertions, 0 deletions
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{