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

Commit ca1f7e6

Browse files
committed
Add users ls integration tests
1 parent 6867ab3 commit ca1f7e6

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

README.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,3 @@ Download the latest [release](https://github.com/cdr/coder-cli/releases):
1717
cd ~/go/bin
1818
tar -xvf ~/Downloads/coder-cli-linux-amd64.tar.gz
1919
```
20-
21-
## Usage
22-
23-
```
24-
$ coder --help
25-
Usage: coder [subcommand] [flags]
26-
27-
coder provides a CLI for working with an existing Coder Enterprise installation.
28-
29-
Commands:
30-
envs get a list of active environment
31-
login authenticate this client for future operations
32-
logout remote local authentication credentials (if any)
33-
sh executes a remote command on the environment
34-
sync establish a one way directory sync to a remote environment
35-
urls get all development urls for external access
36-
version print the currently installed CLI version
37-
config-ssh add your Coder Enterprise environments to ~/.ssh/config
38-
users used to interact with user accounts
39-
40-
```

ci/integration/integration_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"os"
78
"os/exec"
@@ -11,6 +12,8 @@ import (
1112
"time"
1213

1314
"cdr.dev/coder-cli/ci/tcli"
15+
"cdr.dev/coder-cli/internal/entclient"
16+
"cdr.dev/slog"
1417
"cdr.dev/slog/sloggers/slogtest/assert"
1518
)
1619

@@ -110,6 +113,19 @@ func TestCoderCLI(t *testing.T) {
110113
tcli.Error(),
111114
)
112115

116+
var user entclient.User
117+
c.Run(ctx, `coder users ls -o json | jq -c '.[] | select( .username == "charlie")'`).Assert(t,
118+
tcli.Success(),
119+
jsonUnmarshals(&user),
120+
)
121+
assert.Equal(t, "user email is as expected", "charlie@coder.com", user.Email)
122+
assert.Equal(t, "username is as expected", "Charlie", user.Name)
123+
124+
c.Run(ctx, "coder users ls -o human | grep charlie").Assert(t,
125+
tcli.Success(),
126+
tcli.StdoutMatches("charlie"),
127+
)
128+
113129
c.Run(ctx, "coder logout").Assert(t,
114130
tcli.Success(),
115131
)
@@ -118,3 +134,11 @@ func TestCoderCLI(t *testing.T) {
118134
tcli.Error(),
119135
)
120136
}
137+
138+
func jsonUnmarshals(target interface{}) tcli.Assertion {
139+
return func(t *testing.T, r *tcli.CommandResult) {
140+
slog.Helper()
141+
err := json.Unmarshal(r.Stdout, target)
142+
assert.Success(t, "json unmarshals", err)
143+
}
144+
}

cmd/coder/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (cmd usersCmd) Spec() cli.CommandSpec {
2121
return cli.CommandSpec{
2222
Name: "users",
2323
Usage: "[subcommand] <flags>",
24-
Desc: "used to interact with user accounts",
24+
Desc: "interact with user accounts",
2525
}
2626
}
2727

internal/entclient/users.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package entclient
22

3+
// Users gets the list of user accounts
34
func (c Client) Users() ([]User, error) {
45
var u []User
56
err := c.requestBody("GET", "/api/users", nil, &u)

0 commit comments

Comments
 (0)