Skip to content

Commit 169831f

Browse files
committed
done
1 parent e4bd87b commit 169831f

File tree

4 files changed

+14
-35
lines changed

4 files changed

+14
-35
lines changed

cli/cliarg/cliarg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ExactNamedArg(namedArg string, customErrorMessage string) cobra.PositionalA
2121
return func(cmd *cobra.Command, args []string) error {
2222
expectedNumOfArgs := 1
2323
if len(args) != expectedNumOfArgs {
24-
return fmt.Errorf("this command accepts <%s> as an argument, received no arguments. <%s>", namedArg, customErrorMessage)
24+
return fmt.Errorf("this command accepts <%s> as an argument, received no arguments. %s", namedArg, customErrorMessage)
2525
}
2626
return nil
2727
}

cli/cliarg/cliflag_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package cliarg_test
33
import (
44
"testing"
55

6+
"github.com/stretchr/testify/require"
7+
68
"github.com/coder/coder/cli/cliarg"
79
"github.com/coder/coder/cli/clitest"
8-
"github.com/stretchr/testify/require"
910
)
1011

1112
func TestCliarg(t *testing.T) {

cli/delete.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
package cli
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/spf13/cobra"
87

8+
"github.com/coder/coder/cli/cliarg"
99
"github.com/coder/coder/cli/cliui"
1010
"github.com/coder/coder/coderd/database"
1111
"github.com/coder/coder/codersdk"
1212
)
1313

14+
const DeleteError = "Did you forget to pass a workspace name? Run command with --help to see an example."
15+
1416
// nolint
1517
func delete() *cobra.Command {
1618
return &cobra.Command{
1719
Annotations: workspaceCommand,
1820
Use: "delete <workspace>",
1921
Short: "Delete a workspace",
2022
Aliases: []string{"rm"},
21-
Args: cobra.ExactArgs(1),
23+
Args: cliarg.ExactNamedArg("workspace", DeleteError),
2224
RunE: func(cmd *cobra.Command, args []string) error {
23-
fmt.Println("Delete function is running")
2425
client, err := createClient(cmd)
2526
if err != nil {
2627
return err

cli/delete_test.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,18 @@ import (
55

66
"github.com/stretchr/testify/require"
77

8+
"github.com/coder/coder/cli"
89
"github.com/coder/coder/cli/clitest"
9-
"github.com/coder/coder/coderd/coderdtest"
10-
"github.com/coder/coder/pty/ptytest"
1110
)
1211

1312
func TestDelete(t *testing.T) {
1413
t.Parallel()
15-
t.Run("DeleteWithoutParameter", func(t *testing.T) {
14+
t.Run("WithoutParameters", func(t *testing.T) {
1615
t.Parallel()
17-
// Setup
18-
client := coderdtest.New(t, nil)
19-
user := coderdtest.CreateFirstUser(t, client)
20-
coderdtest.NewProvisionerDaemon(t, client)
21-
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
22-
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
23-
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
24-
// When user tries "delete" without a parameter
25-
cmd, root := clitest.New(t, "delete", "")
26-
clitest.SetupConfig(t, client, root)
27-
doneChan := make(chan struct{})
28-
pty := ptytest.New(t)
29-
cmd.SetIn(pty.Input())
30-
cmd.SetOut(pty.Output())
31-
go func() {
32-
defer close(doneChan)
33-
err := cmd.Execute()
34-
require.NoError(t, err)
35-
}()
36-
matches := []string{
37-
"hello world",
38-
}
39-
for i := 0; i < len(matches); i += 1 {
40-
match := matches[i]
41-
pty.ExpectMatch(match)
42-
}
43-
<-doneChan
16+
17+
cmd, _ := clitest.New(t, "delete")
18+
19+
err := cmd.Execute()
20+
require.ErrorContains(t, err, cli.DeleteError)
4421
})
4522
}

0 commit comments

Comments
 (0)