Skip to content

Commit

Permalink
remove public helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed May 19, 2023
1 parent 6835293 commit b05bd3c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
9 changes: 0 additions & 9 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,6 @@ func (p *Provider) ListSources() []*Source {
return sources
}

// GetLastVersion returns the version of the last migration found in the migrations directory
// (sorted by version). If there are no migrations, then 0 is returned.
func (p *Provider) GetLastVersion() int64 {
if len(p.migrations) == 0 {
return 0
}
return p.migrations[len(p.migrations)-1].Version
}

// Ping attempts to ping the database to verify a connection is available.
func (p *Provider) Ping(ctx context.Context) error {
return p.db.PingContext(ctx)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/postgres/allow_missing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestAllowMissingUpWithReset(t *testing.T) {
current, err := p.GetDBVersion(ctx)
check.NoError(t, err)
// Expecting max(version_id) to be highest version in testdata
check.Number(t, current, p.GetLastVersion())
check.Number(t, current, lastVersion(p.ListSources()))
}
// Migrate everything down using Reset.
{
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/postgres/locking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestLockModeAdvisorySession(t *testing.T) {
check.NoError(t, err)

migrations := provider1.ListSources()
maxVersion := provider1.GetLastVersion()
maxVersion := lastVersion(provider1.ListSources())

// Since the lock mode is advisory session, only one of these providers is expected to apply ALL
// the migrations. The other provider should apply NO migrations. The test MUST fail if both
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/postgres/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,10 @@ func newTestEnv(t *testing.T, dir string, options *goose.Options) *testEnv {
opt: opt,
}
}

func lastVersion(migrations []*goose.Source) int64 {
if len(migrations) == 0 {
return 0
}
return migrations[len(migrations)-1].Version
}
6 changes: 3 additions & 3 deletions tests/e2e/postgres/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestUpDownAll(t *testing.T) {
check.Number(t, len(upResult), len(migrations))
currentVersion, err := te.provider.GetDBVersion(ctx)
check.NoError(t, err)
check.Number(t, currentVersion, te.provider.GetLastVersion())
check.Number(t, currentVersion, lastVersion(te.provider.ListSources()))
// Validate the db migration version actually matches what goose claims it is
gotVersion, err := getMaxVersionID(te.db, te.opt.TableName)
check.NoError(t, err)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestMigrateUpByOneWithRedo(t *testing.T) {
te := newTestEnv(t, migrationsDir, nil)
migrations := te.provider.ListSources()
check.NumberNotZero(t, len(migrations))
maxVersion := te.provider.GetLastVersion()
maxVersion := lastVersion(te.provider.ListSources())

for i := 0; i < len(migrations); i++ {
originalUpResult, err := te.provider.UpByOne(ctx)
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestMigrateUpByOne(t *testing.T) {
te := newTestEnv(t, migrationsDir, nil)
migrations := te.provider.ListSources()
check.NumberNotZero(t, len(migrations))
maxVersion := te.provider.GetLastVersion()
maxVersion := lastVersion(te.provider.ListSources())

// Apply all migrations one-by-one.
var counter int
Expand Down

0 comments on commit b05bd3c

Please sign in to comment.