Files
coder/cli/whoami_test.go
Jyotirmoy Bandyopadhayaya b07e3069dd feat: added whomai cmd to coder cli (#13814)
* feat: added whomai cmd to coder cli
* refactor: update Coder CLI's whoami command to use client URL instead of deployment config
* feat(cli): add unit tests for the whoami command
* chore(docs): add coder command to fetch authenticated user info
* chore(doc): update help desc
2024-07-09 13:23:11 -05:00

38 lines
790 B
Go

package cli_test
import (
"bytes"
"testing"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/coderd/coderdtest"
)
func TestWhoami(t *testing.T) {
t.Parallel()
t.Run("InitialUserNoTTY", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
root, _ := clitest.New(t, "login", client.URL.String())
err := root.Run()
require.Error(t, err)
})
t.Run("OK", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)
inv, root := clitest.New(t, "whoami")
clitest.SetupConfig(t, client, root)
buf := new(bytes.Buffer)
inv.Stdout = buf
err := inv.Run()
require.NoError(t, err)
whoami := buf.String()
require.NotEmpty(t, whoami)
})
}