From b05bd3c0c6489fb37bb79af04f504f6f4f8b85d7 Mon Sep 17 00:00:00 2001 From: Mike Fridman Date: Fri, 19 May 2023 19:41:04 -0400 Subject: [PATCH] remove public helper method --- provider.go | 9 --------- tests/e2e/postgres/allow_missing_test.go | 2 +- tests/e2e/postgres/locking_test.go | 2 +- tests/e2e/postgres/main_test.go | 7 +++++++ tests/e2e/postgres/migrations_test.go | 6 +++--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/provider.go b/provider.go index c6dcfb93f..05f5b85d1 100644 --- a/provider.go +++ b/provider.go @@ -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) diff --git a/tests/e2e/postgres/allow_missing_test.go b/tests/e2e/postgres/allow_missing_test.go index ff80fad09..2e61d8eb0 100644 --- a/tests/e2e/postgres/allow_missing_test.go +++ b/tests/e2e/postgres/allow_missing_test.go @@ -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. { diff --git a/tests/e2e/postgres/locking_test.go b/tests/e2e/postgres/locking_test.go index d629b5df2..0ea013e6b 100644 --- a/tests/e2e/postgres/locking_test.go +++ b/tests/e2e/postgres/locking_test.go @@ -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 diff --git a/tests/e2e/postgres/main_test.go b/tests/e2e/postgres/main_test.go index 6012300dc..dae3ba03e 100644 --- a/tests/e2e/postgres/main_test.go +++ b/tests/e2e/postgres/main_test.go @@ -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 +} diff --git a/tests/e2e/postgres/migrations_test.go b/tests/e2e/postgres/migrations_test.go index c6ac3b5be..3cf360c73 100644 --- a/tests/e2e/postgres/migrations_test.go +++ b/tests/e2e/postgres/migrations_test.go @@ -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) @@ -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) @@ -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