Skip to content

Commit

Permalink
chore: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Oct 26, 2023
1 parent 42a4245 commit 42744d3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
17 changes: 0 additions & 17 deletions internal/db/diff/migra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,6 @@ func TestRunMigra(t *testing.T) {
assert.ErrorIs(t, err, os.ErrNotExist)
})

t.Run("throws error on missing database", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, utils.WriteConfig(fsys, false))
// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
defer gock.OffAll()
gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/containers/supabase_db_").
ReplyError(errors.New("network error"))
// Run test
err := RunMigra(context.Background(), []string{"public"}, "", pgconn.Config{Host: "127.0.0.1"}, fsys)
// Check error
assert.ErrorIs(t, err, utils.ErrNotRunning)
assert.Empty(t, apitest.ListUnmatchedRequests())
})

t.Run("throws error on failure to load user schemas", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
Expand Down
2 changes: 1 addition & 1 deletion internal/db/pull/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var dbConfig = pgconn.Config{
Host: "127.0.0.1",
Host: "db.supabase.co",
Port: 5432,
User: "admin",
Password: "password",
Expand Down
8 changes: 7 additions & 1 deletion internal/db/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ func TestMigrationPush(t *testing.T) {
conn.Query(list.LIST_MIGRATION_VERSION).
ReplyError(pgerrcode.InvalidCatalogName, `database "target" does not exist`)
// Run test
err := Run(context.Background(), false, false, false, false, pgconn.Config{Host: "db.supabase.co"}, fsys, conn.Intercept)
err := Run(context.Background(), false, false, false, false, pgconn.Config{
Host: "db.supabase.co",
Port: 5432,
User: "admin",
Password: "password",
Database: "postgres",
}, fsys, conn.Intercept)
// Check error
assert.ErrorContains(t, err, `ERROR: database "target" does not exist (SQLSTATE 3D000)`)
})
Expand Down
2 changes: 1 addition & 1 deletion internal/db/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.F
return err
}
}
if config.Host != "127.0.0.1" {
if !utils.IsLoopback(config.Host) {
if shouldReset := utils.PromptYesNo("Confirm resetting the remote database?", true, os.Stdin); !shouldReset {
return context.Canceled
}
Expand Down
2 changes: 1 addition & 1 deletion internal/migration/squash/squash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Run(ctx context.Context, version string, config pgconn.Config, fsys afero.F
return err
}
// 2. Update migration history
if shouldUpdate := utils.PromptYesNo("Update remote migration history table?", true, os.Stdin); !shouldUpdate {
if utils.IsLoopback(config.Host) || !utils.PromptYesNo("Update remote migration history table?", true, os.Stdin) {
return nil
}
return baselineMigrations(ctx, config, version, fsys, options...)
Expand Down
4 changes: 2 additions & 2 deletions internal/migration/squash/squash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

var dbConfig = pgconn.Config{
Host: "127.0.0.1",
Host: "db.supabase.co",
Port: 5432,
User: "admin",
Password: "password",
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestSquashCommand(t *testing.T) {
Query(repair.INSERT_MIGRATION_VERSION, "1", "target", "{}").
Reply("INSERT 1")
// Run test
err := Run(context.Background(), "", pgconn.Config{}, fsys, conn.Intercept)
err := Run(context.Background(), "", pgconn.Config{Host: "127.0.0.1"}, fsys, conn.Intercept)
// Check error
assert.NoError(t, err)
assert.Empty(t, apitest.ListUnmatchedRequests())
Expand Down

0 comments on commit 42744d3

Please sign in to comment.