Skip to content

Commit

Permalink
chore: apply PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Sep 9, 2024
1 parent 5e29d4c commit 5e1f197
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 62 deletions.
17 changes: 1 addition & 16 deletions internal/db/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,7 @@ func restartServices(ctx context.Context) error {
}

func listServicesToRestart() []string {
var services []string

if utils.Config.Storage.Enabled {
services = append(services, utils.StorageId)
}
if utils.Config.Realtime.Enabled {
services = append(services, utils.RealtimeId)
}
if utils.Config.Db.Pooler.Enabled {
services = append(services, utils.PoolerId)
}
if utils.Config.Auth.Enabled {
services = append(services, utils.GotrueId)
}

return services
return []string{utils.StorageId, utils.GotrueId, utils.RealtimeId, utils.PoolerId}
}

func resetRemote(ctx context.Context, version string, config pgconn.Config, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
Expand Down
46 changes: 0 additions & 46 deletions internal/db/reset/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ func TestRestartDatabase(t *testing.T) {
utils.GotrueId = "test-auth"
utils.RealtimeId = "test-realtime"
utils.PoolerId = "test-pooler"
utils.Config.Storage.Enabled = true
utils.Config.Auth.Enabled = true
utils.Config.Realtime.Enabled = true
for _, container := range []string{utils.StorageId, utils.GotrueId, utils.RealtimeId} {
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + container + "/restart").
Expand Down Expand Up @@ -324,49 +321,6 @@ func TestRestartDatabase(t *testing.T) {
assert.ErrorContains(t, err, "test-reset container is not running: exited")
assert.Empty(t, apitest.ListUnmatchedRequests())
})
t.Run("restarts only enabled services", func(t *testing.T) {
utils.DbId = "test-reset"
// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
defer gock.OffAll()
// Restarts postgres
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.DbId + "/restart").
Reply(http.StatusOK)
gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.DbId + "/json").
Reply(http.StatusOK).
JSON(types.ContainerJSON{ContainerJSONBase: &types.ContainerJSONBase{
State: &types.ContainerState{
Running: true,
Health: &types.Health{Status: "healthy"},
},
}})
// Restarts enabled services
utils.StorageId = "test-storage"
utils.PoolerId = "test-pooler"
utils.GotrueId = "test-auth"
utils.RealtimeId = "test-realtime"
utils.Config.Auth.Enabled = true
utils.Config.Realtime.Enabled = true
utils.Config.Db.Pooler.Enabled = false
utils.Config.Storage.Enabled = false
for _, container := range []string{utils.GotrueId, utils.RealtimeId} {
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + container + "/restart").
Reply(http.StatusOK)
}
for _, container := range []string{utils.StorageId, utils.PoolerId} {
gock.New(utils.Docker.DaemonHost()).
Post("/v" + utils.Docker.ClientVersion() + "/containers/" + container + "/restart").
Reply(http.StatusServiceUnavailable)
}
// Run test
err := RestartDatabase(context.Background(), io.Discard)
// Check error
assert.NoError(t, err)
assert.Empty(t, apitest.ListUnmatchedRequests())
})
}

var escapedSchemas = append(migration.ManagedSchemas, "extensions", "public")
Expand Down

0 comments on commit 5e1f197

Please sign in to comment.