aboutsummaryrefslogtreecommitdiffstats
path: root/internal/services/migration_test.go
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-03-02 11:04:00 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2024-03-02 11:04:00 -0500
commita37df93853def914dbda165cdcf09ae8e0305ec3 (patch)
tree41fb3a459db99d1f0ec2ed2e00d4ca580a5d0c46 /internal/services/migration_test.go
parentimprove wording (diff)
downloadcli-a37df93853def914dbda165cdcf09ae8e0305ec3.zip
Remove Latest() from migration fs repo in favor of using List on service
Diffstat (limited to 'internal/services/migration_test.go')
-rw-r--r--internal/services/migration_test.go50
1 files changed, 43 insertions, 7 deletions
diff --git a/internal/services/migration_test.go b/internal/services/migration_test.go
index 1087398..0c30c76 100644
--- a/internal/services/migration_test.go
+++ b/internal/services/migration_test.go
@@ -440,7 +440,7 @@ func TestCreateMigration_CreateErr(t *testing.T) {
func TestCreateMigration_LatestErr(t *testing.T) {
expectedErr := errors.New("error!")
migrationFsRepo := &bolttest.MockMigrationFsRepo{
- LatestReturnValue: bolttest.LatestReturnValue{
+ ListReturnValue: bolttest.ListReturnValue{
Err: expectedErr,
},
}
@@ -464,9 +464,11 @@ func TestCreateMigration_LatestErr(t *testing.T) {
func TestCreateMigration_SequentialVersionIncrements(t *testing.T) {
migrationFsRepo := &bolttest.MockMigrationFsRepo{
- LatestReturnValue: bolttest.LatestReturnValue{
- Migration: &models.Migration{Version: "001"},
- Err: nil,
+ ListReturnValue: bolttest.ListReturnValue{
+ Migrations: map[string]*models.Migration{
+ "001": {Version: "001"},
+ },
+ Err: nil,
},
CreateReturnValue: bolttest.CreateReturnValue{
Err: nil,
@@ -490,11 +492,45 @@ func TestCreateMigration_SequentialVersionIncrements(t *testing.T) {
assert.Equal(t, migration.Version, "002")
}
+func TestCreateMigration_SequentialVersionIncrementsLatestVersion(t *testing.T) {
+ migrationFsRepo := &bolttest.MockMigrationFsRepo{
+ ListReturnValue: bolttest.ListReturnValue{
+ Migrations: map[string]*models.Migration{
+ "001": {Version: "001"},
+ "002": {Version: "002"},
+ "003": {Version: "003"},
+ },
+ Err: nil,
+ },
+ CreateReturnValue: bolttest.CreateReturnValue{
+ Err: nil,
+ },
+ }
+ migrationDbRepo := &bolttest.MockMigrationDBRepo{}
+ svc := NewMigrationService(
+ migrationDbRepo,
+ migrationFsRepo,
+ configloader.Config{
+ Migrations: configloader.MigrationsConfig{
+ VersionStyle: configloader.VersionStyleSequential,
+ },
+ },
+ bolttest.NullOutputter{},
+ )
+
+ migration, err := svc.CreateMigration("new migration")
+
+ assert.Nil(t, err)
+ assert.Equal(t, migration.Version, "004")
+}
+
func TestCreateMigration_SequentialVersionIncrementsParsingErr(t *testing.T) {
migrationFsRepo := &bolttest.MockMigrationFsRepo{
- LatestReturnValue: bolttest.LatestReturnValue{
- Migration: &models.Migration{Version: "abc"},
- Err: nil,
+ ListReturnValue: bolttest.ListReturnValue{
+ Migrations: map[string]*models.Migration{
+ "abc": {Version: "abc"},
+ },
+ Err: nil,
},
CreateReturnValue: bolttest.CreateReturnValue{
Err: nil,