Skip to content

Commit

Permalink
feat(start): automatically run the status command if already started (#…
Browse files Browse the repository at this point in the history
…2980)

* feat(start): automatically run the status command if already started

Rather than asking the user to run the command to get the values
Run the command for him so start command always return the infos
of the running stack.

* fix: test

* fix: test
  • Loading branch information
avallete authored Dec 30, 2024
1 parent d3acc10 commit 9f6f271
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignore
}
if err := utils.AssertSupabaseDbIsRunning(); err == nil {
fmt.Fprintln(os.Stderr, utils.Aqua("supabase start")+" is already running.")
utils.CmdSuggestion = fmt.Sprintf("Run %s to show status of local Supabase containers.", utils.Aqua("supabase status"))
return nil
names := status.CustomName{}
return status.Run(ctx, names, utils.OutputPretty, fsys)
} else if !errors.Is(err, utils.ErrNotRunning) {
return err
}
Expand Down
19 changes: 18 additions & 1 deletion internal/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ func TestStartCommand(t *testing.T) {
assert.Empty(t, apitest.ListUnmatchedRequests())
})

t.Run("noop if database is already running", func(t *testing.T) {
t.Run("show status if database is already running", func(t *testing.T) {
var running []types.Container
for _, name := range utils.GetDockerIds() {
running = append(running, types.Container{
Names: []string{name + "_test"},
})
}
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, utils.WriteConfig(fsys, false))
Expand All @@ -68,6 +74,17 @@ func TestStartCommand(t *testing.T) {
Get("/v" + utils.Docker.ClientVersion() + "/containers").
Reply(http.StatusOK).
JSON(types.ContainerJSON{})

gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/containers/supabase_db_start/json").
Reply(http.StatusOK).
JSON(types.ContainerJSON{ContainerJSONBase: &types.ContainerJSONBase{
State: &types.ContainerState{Running: true},
}})
gock.New(utils.Docker.DaemonHost()).
Get("/v" + utils.Docker.ClientVersion() + "/containers/json").
Reply(http.StatusOK).
JSON(running)
// Run test
err := Run(context.Background(), fsys, []string{}, false)
// Check error
Expand Down

0 comments on commit 9f6f271

Please sign in to comment.