Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/workspace/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
}
deleteCmd := &cobra.Command{
Use: "delete [flags] [workspace-path|workspace-name]",
Aliases: []string{"rm"},
Aliases: []string{"rm", "down"},

Check failure on line 33 in cmd/workspace/delete.go

View workflow job for this annotation

GitHub Actions / Lint

string `down` has 4 occurrences, make it a constant (goconst)
Short: "Delete a workspace",
Long: `Delete a workspace by path or name.

Aliases "rm" and "down" perform the same full Devsy workspace teardown.
For Docker Compose workspaces, teardown uses Docker/Podman Compose down.

Use --ignore-not-found to treat a missing workspace as success.`,
RunE: func(cobraCmd *cobra.Command, args []string) error {
return cmd.Run(cobraCmd, args)
Expand Down
83 changes: 83 additions & 0 deletions cmd/workspace/delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package workspace

import (
"bytes"
"testing"

"github.com/devsy-org/devsy/cmd/flags"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDeleteCmd_Aliases(t *testing.T) {
deleteCmd := NewDeleteCmd(&flags.GlobalFlags{})

assert.ElementsMatch(t, []string{"rm", "down"}, deleteCmd.Aliases)

Check failure on line 15 in cmd/workspace/delete_test.go

View workflow job for this annotation

GitHub Actions / Lint

string `down` has 4 occurrences, make it a constant (goconst)
}

func TestDeleteCmd_Resolution(t *testing.T) {
workspaceCmd := NewWorkspaceCmd(&flags.GlobalFlags{})

testCases := []struct {
name string
args []string
}{
{
name: "canonical delete",
args: []string{"delete"},
},
{
name: "rm alias",
args: []string{"rm"},
},
{
name: "down alias",
args: []string{"down"},
},
{
name: "down alias with positional workspace",
args: []string{"down", "my-workspace"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
resolved, remainingArgs, err := workspaceCmd.Find(tc.args)
require.NoError(t, err)
require.NotNil(t, resolved)
assert.Equal(t, "delete", resolved.Name())
if len(tc.args) > 1 {
assert.Equal(t, tc.args[1:], remainingArgs)
} else {
assert.Empty(t, remainingArgs)
}
})
}
}

func TestDeleteCmd_HelpExposesDownAlias(t *testing.T) {
deleteCmd := NewDeleteCmd(&flags.GlobalFlags{})

var buf bytes.Buffer
deleteCmd.SetOut(&buf)
err := deleteCmd.Help()
require.NoError(t, err)

helpOutput := buf.String()
assert.Contains(t, helpOutput, "Aliases:")
assert.Contains(t, helpOutput, "down")
assert.Contains(t, helpOutput, "rm")
}

func TestDeleteCmd_Completion(t *testing.T) {
workspaceCmd := NewWorkspaceCmd(&flags.GlobalFlags{})

var buf bytes.Buffer
err := workspaceCmd.GenBashCompletion(&buf)
require.NoError(t, err)

completionOutput := buf.String()
assert.Contains(t, completionOutput, `"down"`)
assert.Contains(t, completionOutput, `"rm"`)
assert.Contains(t, completionOutput, `"delete"`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ Run the following command to delete a workspace:
devsy workspace delete my-workspace
```

`devsy workspace down` (as well as `rm`) is an alias for `devsy workspace delete`. It performs the same full Devsy workspace teardown:
```
devsy workspace down my-workspace
```

For Docker Compose-backed workspaces, teardown uses Compose `down` (with `--remove-volumes` remaining an opt-in flag to remove associated named volumes). Use `devsy workspace stop` when you want to stop a workspace while retaining its configuration and state so it can be started again later.

If deletion fails because the Provider is not reachable anymore or another error has occurred, you can also force delete a workspace via:
```
devsy workspace delete my-workspace --force
Expand Down
Loading