Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 88b6ebc

Browse files
committed
fixup! fixup! fixup! fixup! Add integration tests for Secrets commands
1 parent 42e024e commit 88b6ebc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ci/integration/integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestCoderCLI(t *testing.T) {
7070
var user entclient.User
7171
c.Run(ctx, `coder users ls -o json | jq -c '.[] | select( .username == "charlie")'`).Assert(t,
7272
tcli.Success(),
73-
jsonUnmarshals(&user),
73+
stdoutUnmarshalsJSON(&user),
7474
)
7575
assert.Equal(t, "user email is as expected", "charlie@coder.com", user.Email)
7676
assert.Equal(t, "username is as expected", "Charlie", user.Name)
@@ -148,7 +148,7 @@ func TestSecrets(t *testing.T) {
148148
)
149149
}
150150

151-
func jsonUnmarshals(target interface{}) tcli.Assertion {
151+
func stdoutUnmarshalsJSON(target interface{}) tcli.Assertion {
152152
return func(t *testing.T, r *tcli.CommandResult) {
153153
slog.Helper()
154154
err := json.Unmarshal(r.Stdout, target)

cmd/coder/users.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77

88
"cdr.dev/coder-cli/internal/x/xtabwriter"
9+
"cdr.dev/coder-cli/internal/x/xvalidate"
910
"github.com/spf13/pflag"
1011

1112
"go.coder.com/cli"
@@ -37,6 +38,7 @@ type listCmd struct {
3738
}
3839

3940
func (cmd *listCmd) Run(fl *pflag.FlagSet) {
41+
xvalidate.Validate(cmd)
4042
entClient := requireAuth()
4143

4244
users, err := entClient.Users()
@@ -61,7 +63,6 @@ func (cmd *listCmd) Run(fl *pflag.FlagSet) {
6163
default:
6264
exitUsage(fl)
6365
}
64-
6566
}
6667

6768
func (cmd *listCmd) RegisterFlags(fl *pflag.FlagSet) {
@@ -75,3 +76,10 @@ func (cmd *listCmd) Spec() cli.CommandSpec {
7576
Desc: "list all users",
7677
}
7778
}
79+
80+
func (cmd *listCmd) Validate() (e []error) {
81+
if !(cmd.outputFmt == "json" || cmd.outputFmt == "human") {
82+
e = append(e, fmt.Errorf(`--output must be "json" or "human"`))
83+
}
84+
return e
85+
}

0 commit comments

Comments
 (0)