Skip to content

Commit 2669191

Browse files
authored
feat(cli): add unit tests for the whoami command
1 parent 0de8bd4 commit 2669191

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cli/whoami_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cli_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/v2/cli/clitest"
10+
"github.com/coder/coder/v2/coderd/coderdtest"
11+
)
12+
13+
func TestWhoami(t *testing.T) {
14+
t.Parallel()
15+
16+
t.Run("InitialUserNoTTY", func(t *testing.T) {
17+
t.Parallel()
18+
client := coderdtest.New(t, nil)
19+
root, _ := clitest.New(t, "login", client.URL.String())
20+
err := root.Run()
21+
require.Error(t, err)
22+
})
23+
24+
t.Run("OK", func(t *testing.T) {
25+
t.Parallel()
26+
client := coderdtest.New(t, nil)
27+
_ = coderdtest.CreateFirstUser(t, client)
28+
inv, root := clitest.New(t, "whoami")
29+
clitest.SetupConfig(t, client, root)
30+
buf := new(bytes.Buffer)
31+
inv.Stdout = buf
32+
err := inv.Run()
33+
require.NoError(t, err)
34+
whoami := buf.String()
35+
require.NotEmpty(t, whoami)
36+
})
37+
}

0 commit comments

Comments
 (0)