Skip to content

Commit e553c34

Browse files
Add tests for missing version schema
Ensure that `roll.LatestVersionRemote` returns the expected error: * When migrations have been applied but none have a version schema. * When no migrations have been applied.
1 parent b5968c8 commit e553c34

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

pkg/roll/latest_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,40 @@ func TestLatestVersionRemote(t *testing.T) {
107107
})
108108
})
109109

110+
t.Run("returns an error if migrations have been applied but none have a version schema", func(t *testing.T) {
111+
opts := []roll.Option{roll.WithVersionSchema(false)}
112+
113+
testutils.WithMigratorInSchemaAndConnectionToContainerWithOptions(t, "public", opts, func(m *roll.Roll, _ *sql.DB) {
114+
ctx := context.Background()
115+
116+
// Start and complete a migration
117+
err := m.Start(ctx, &migrations.Migration{
118+
Name: "01_first_migration",
119+
Operations: migrations.Operations{
120+
&migrations.OpRawSQL{Up: "SELECT 1"},
121+
},
122+
}, backfill.NewConfig())
123+
require.NoError(t, err)
124+
err = m.Complete(ctx)
125+
require.NoError(t, err)
126+
127+
// Get the latest migration in the target schema
128+
_, err = m.LatestVersionRemote(ctx)
129+
130+
// Assert expected error
131+
assert.ErrorIs(t, err, roll.ErrNoVersionSchema)
132+
})
133+
})
134+
110135
t.Run("returns an error if no migrations have been applied", func(t *testing.T) {
111136
testutils.WithMigratorAndConnectionToContainer(t, func(m *roll.Roll, _ *sql.DB) {
112137
ctx := context.Background()
113138

114-
// Get the latest migration in the directory
139+
// Get the latest migration in the target schema
115140
_, err := m.LatestVersionRemote(ctx)
116141

117142
// Assert expected error
118-
assert.ErrorIs(t, err, roll.ErrNoMigrationApplied)
143+
assert.ErrorIs(t, err, roll.ErrNoVersionSchema)
119144
})
120145
})
121146
}

0 commit comments

Comments
 (0)