diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-13 22:20:16 -0800 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-13 22:20:16 -0800 |
| commit | 7026e3861a5712ced6f2006f282c8386b4db106e (patch) | |
| tree | 18db906e76c1736a831f345b4832db91964c960a /internal/services | |
| parent | Remove timestamp version style in favor of always using sequential (diff) | |
| download | cli-7026e3861a5712ced6f2006f282c8386b4db106e.zip | |
Pad new migrations to 4 digits
Diffstat (limited to 'internal/services')
| -rw-r--r-- | internal/services/migration_test.go | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/internal/services/migration_test.go b/internal/services/migration_test.go index 0496299..4b5bdf0 100644 --- a/internal/services/migration_test.go +++ b/internal/services/migration_test.go @@ -31,26 +31,26 @@ func TestListMigrations(t *testing.T) { // Ensure one local fs migration shows up as expected. { localFilesystemMigrations: []*models.Migration{ - {Version: "001", Applied: false}, + {Version: "0001", Applied: false}, }, remoteAppliedMigrations: []*models.Migration{}, sortOrder: SortOrderAsc, expectedMigrations: []*models.Migration{ - {Version: "001", Applied: false}, + {Version: "0001", Applied: false}, }, }, // Ensure that one local fs migration and one remote applied migration // for the same version returns one applied migration. { localFilesystemMigrations: []*models.Migration{ - {Version: "001", Applied: false}, + {Version: "0001", Applied: false}, }, remoteAppliedMigrations: []*models.Migration{ - {Version: "001", Applied: true}, + {Version: "0001", Applied: true}, }, sortOrder: SortOrderAsc, expectedMigrations: []*models.Migration{ - {Version: "001", Applied: true}, + {Version: "0001", Applied: true}, }, }, // Ensure that any applied migrations that don't exist locally @@ -58,7 +58,7 @@ func TestListMigrations(t *testing.T) { { localFilesystemMigrations: []*models.Migration{}, remoteAppliedMigrations: []*models.Migration{ - {Version: "001", Applied: true}, + {Version: "0001", Applied: true}, }, sortOrder: SortOrderAsc, expectedMigrations: []*models.Migration{}, @@ -72,12 +72,12 @@ func TestListMigrations(t *testing.T) { {Version: "1009"}, {Version: "190"}, {Version: "110"}, - {Version: "001"}, + {Version: "0001"}, }, remoteAppliedMigrations: []*models.Migration{}, sortOrder: SortOrderAsc, expectedMigrations: []*models.Migration{ - {Version: "001"}, + {Version: "0001"}, {Version: "110"}, {Version: "190"}, {Version: "1009"}, @@ -89,7 +89,7 @@ func TestListMigrations(t *testing.T) { // Ensure that migrations are sorted in desc order for sequential migrations { localFilesystemMigrations: []*models.Migration{ - {Version: "001"}, + {Version: "0001"}, {Version: "110"}, {Version: "190"}, {Version: "1009"}, @@ -106,7 +106,7 @@ func TestListMigrations(t *testing.T) { {Version: "1009"}, {Version: "190"}, {Version: "110"}, - {Version: "001"}, + {Version: "0001"}, }, }, } @@ -263,7 +263,7 @@ func TestCreateMigration(t *testing.T) { migration, err := svc.CreateMigration("new migration") assert.Nil(t, err) - check.Equal(t, migration.Version, "001") + check.Equal(t, migration.Version, "0001") check.Equal(t, migration.Message, "new migration") check.Equal(t, migration.Applied, false) } @@ -283,7 +283,7 @@ func TestCreateMigration_NilDbRepo(t *testing.T) { migration, err := svc.CreateMigration("new migration") assert.Nil(t, err) - check.Equal(t, migration.Version, "001") + check.Equal(t, migration.Version, "0001") check.Equal(t, migration.Message, "new migration") check.Equal(t, migration.Applied, false) } @@ -332,7 +332,7 @@ func TestCreateMigration_VersionIncrements(t *testing.T) { migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ Migrations: map[string]*models.Migration{ - "001": {Version: "001"}, + "0001": {Version: "0001"}, }, Err: nil, }, @@ -350,16 +350,16 @@ func TestCreateMigration_VersionIncrements(t *testing.T) { migration, err := svc.CreateMigration("new migration") assert.Nil(t, err) - assert.Equal(t, migration.Version, "002") + assert.Equal(t, migration.Version, "0002") } func TestCreateMigration_VersionIncrementsLatestVersion(t *testing.T) { migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ Migrations: map[string]*models.Migration{ - "001": {Version: "001"}, - "002": {Version: "002"}, - "003": {Version: "003"}, + "0001": {Version: "0001"}, + "0002": {Version: "0002"}, + "0003": {Version: "0003"}, }, Err: nil, }, @@ -377,7 +377,7 @@ func TestCreateMigration_VersionIncrementsLatestVersion(t *testing.T) { migration, err := svc.CreateMigration("new migration") assert.Nil(t, err) - assert.Equal(t, migration.Version, "004") + assert.Equal(t, migration.Version, "0004") } func TestCreateMigration_VersionIncrementsParsingErr(t *testing.T) { @@ -557,8 +557,8 @@ func TestApplyAllMigrations_ListMigrationsErr(t *testing.T) { func TestApplyAllMigrations_AppliesNothingIfAllApplied(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: true}, - "002": {Version: "002", Applied: true}, + "0001": {Version: "0001", Applied: true}, + "0002": {Version: "0002", Applied: true}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -582,7 +582,7 @@ func TestApplyAllMigrations_AppliesNothingIfAllApplied(t *testing.T) { func TestApplyAllMigrations_ApplyMigrationErr(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: false}, + "0001": {Version: "0001", Applied: false}, } expectedErr := errors.New("error!") migrationFsRepo := &bolttest.MockMigrationFsRepo{ @@ -622,14 +622,14 @@ func TestApplyUpToVersion_ListMigrationsErr(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.ApplyUpToVersion("001") + err := svc.ApplyUpToVersion("0001") assert.ErrorIs(t, err, expectedErr) } func TestApplyUpToVersion_TargetMigrationNotFound(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: false}, + "0001": {Version: "0001", Applied: false}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -643,14 +643,14 @@ func TestApplyUpToVersion_TargetMigrationNotFound(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.ApplyUpToVersion("002") + err := svc.ApplyUpToVersion("0002") - assert.ErrorContains(t, err, "migration with version 002 does not exist") + assert.ErrorContains(t, err, "migration with version 0002 does not exist") } func TestApplyUpToVersion_TargetMigrationAlreadyApplied(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: true}, + "0001": {Version: "0001", Applied: true}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -664,14 +664,14 @@ func TestApplyUpToVersion_TargetMigrationAlreadyApplied(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.ApplyUpToVersion("001") + err := svc.ApplyUpToVersion("0001") - assert.ErrorContains(t, err, "migration with version 001 is already applied") + assert.ErrorContains(t, err, "migration with version 0001 is already applied") } func TestApplyUpToVersion_ApplyMigrationErr(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: false}, + "0001": {Version: "0001", Applied: false}, } expectedErr := errors.New("error!") migrationFsRepo := &bolttest.MockMigrationFsRepo{ @@ -689,16 +689,16 @@ func TestApplyUpToVersion_ApplyMigrationErr(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.ApplyUpToVersion("001") + err := svc.ApplyUpToVersion("0001") assert.ErrorIs(t, err, expectedErr) } func TestApplyUpToVersion_AppliesMigrations(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: false}, - "002": {Version: "002", Applied: false}, - "003": {Version: "003", Applied: false}, + "0001": {Version: "0001", Applied: false}, + "0002": {Version: "0002", Applied: false}, + "0003": {Version: "0003", Applied: false}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -712,7 +712,7 @@ func TestApplyUpToVersion_AppliesMigrations(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.ApplyUpToVersion("002") + err := svc.ApplyUpToVersion("0002") assert.Nil(t, err) assert.Equal(t, migrationFsRepo.ReadUpgradeScriptCallCount, 2) @@ -861,14 +861,14 @@ func TestRevertDownToVersion_ListMigrationsErr(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.RevertDownToVersion("001") + err := svc.RevertDownToVersion("0001") assert.ErrorIs(t, err, expectedErr) } func TestRevertDownToVersion_TargetMigrationNotFound(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: true}, + "0001": {Version: "0001", Applied: true}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -882,14 +882,14 @@ func TestRevertDownToVersion_TargetMigrationNotFound(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.RevertDownToVersion("002") + err := svc.RevertDownToVersion("0002") - assert.ErrorContains(t, err, "migration with version 002 does not exist") + assert.ErrorContains(t, err, "migration with version 0002 does not exist") } func TestRevertDownToVersion_TargetMigrationNotApplied(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: false}, + "0001": {Version: "0001", Applied: false}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -903,14 +903,14 @@ func TestRevertDownToVersion_TargetMigrationNotApplied(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.RevertDownToVersion("001") + err := svc.RevertDownToVersion("0001") - assert.ErrorContains(t, err, "migration with version 001 isn't applied") + assert.ErrorContains(t, err, "migration with version 0001 isn't applied") } func TestRevertDownToVersion_RevertMigrationErr(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: true}, + "0001": {Version: "0001", Applied: true}, } expectedErr := errors.New("error!") migrationFsRepo := &bolttest.MockMigrationFsRepo{ @@ -928,16 +928,16 @@ func TestRevertDownToVersion_RevertMigrationErr(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.RevertDownToVersion("001") + err := svc.RevertDownToVersion("0001") assert.ErrorIs(t, err, expectedErr) } func TestRevertDownToVersion_RevertsMigrations(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: true}, - "002": {Version: "002", Applied: true}, - "003": {Version: "003", Applied: false}, + "0001": {Version: "0001", Applied: true}, + "0002": {Version: "0002", Applied: true}, + "0003": {Version: "0003", Applied: false}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -951,7 +951,7 @@ func TestRevertDownToVersion_RevertsMigrations(t *testing.T) { bolttest.NullOutputter{}, ) - err := svc.RevertDownToVersion("001") + err := svc.RevertDownToVersion("0001") assert.Nil(t, err) assert.Equal(t, migrationFsRepo.ReadDowngradeScriptCallCount, 2) @@ -978,8 +978,8 @@ func TestRevertAllMigrations_ListMigrationsErr(t *testing.T) { func TestRevertAllMigrations_RevertsNothingIfNoneApplied(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: false}, - "002": {Version: "002", Applied: false}, + "0001": {Version: "0001", Applied: false}, + "0002": {Version: "0002", Applied: false}, } migrationFsRepo := &bolttest.MockMigrationFsRepo{ ListReturnValue: bolttest.ListReturnValue{ @@ -1003,7 +1003,7 @@ func TestRevertAllMigrations_RevertsNothingIfNoneApplied(t *testing.T) { func TestRevertAllMigrations_RevertMigrationErr(t *testing.T) { migrations := map[string]*models.Migration{ - "001": {Version: "001", Applied: true}, + "0001": {Version: "0001", Applied: true}, } expectedErr := errors.New("error!") migrationFsRepo := &bolttest.MockMigrationFsRepo{ |