Skip to content

Commit

Permalink
chore: add start runtime test
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete committed Oct 23, 2024
1 parent b8c121d commit f47fb1b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/db/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/supabase/cli/internal/testing/apitest"
"github.com/supabase/cli/internal/testing/fstest"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/cast"
"github.com/supabase/cli/pkg/pgtest"
)

Expand Down Expand Up @@ -308,3 +309,49 @@ func TestSetupDatabase(t *testing.T) {
assert.Empty(t, apitest.ListUnmatchedRequests())
})
}
func TestStartDatabaseWithCustomSettings(t *testing.T) {
t.Run("starts database with custom MaxConnections", func(t *testing.T) {
// Setup
utils.Config.Db.MajorVersion = 15
utils.DbId = "supabase_db_test"
utils.ConfigId = "supabase_config_test"
utils.Config.Db.Port = 5432
utils.Config.Db.Settings.MaxConnections = cast.Ptr(uint(200))

// Setup in-memory fs
fsys := afero.NewMemMapFs()

// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
defer gock.OffAll()
gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.DbId).
Reply(http.StatusNotFound).
JSON(volume.Volume{})
apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Db.Image), utils.DbId)
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: types.Healthy},
},
}})

// Setup mock postgres
conn := pgtest.NewConn()
defer conn.Close(t)

// Run test
err := StartDatabase(context.Background(), fsys, io.Discard, conn.Intercept)

// Check error
assert.NoError(t, err)
assert.Empty(t, apitest.ListUnmatchedRequests())

// Check if the custom MaxConnections setting was applied
config := NewContainerConfig()
assert.Contains(t, config.Entrypoint[2], "max_connections = 200")
})
}

0 comments on commit f47fb1b

Please sign in to comment.