10000 Add helper text to unauthorized error messages by AbhineetJain · Pull Request #1670 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

Add helper text to unauthorized error messages #1670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 23, 2022
Merged
Prev Previous commit
Next Next commit
fix lint error, add unit tests
  • Loading branch information
AbhineetJain committed May 23, 2022
commit 1f607010d1fb158987e8223c1c325783d5111348
54 changes: 38 additions & 16 deletions cli/userlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,42 @@ import (
)

func TestUserList(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
coderdtest.CreateFirstUser(t, client)
cmd, root := clitest.New(t, "users", "list")
clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{})
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
}()
pty.ExpectMatch("coder.com")
<-doneChan
t.Run("FormatCobraError", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
coderdtest.CreateFirstUser(t, client)
cmd, root := clitest.New(t, "users", "list")
clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{})
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
go func() {
defer close(doneChan)
err := cmd.Execute()
require.NoError(t, err)
}()
pty.ExpectMatch("coder.com")
<-doneChan
})
t.Run("NoURLFileErrorHasHelperText", func(t *testing.T) {
t.Parallel()

cmd, _ := clitest.New(t, "users", "list")

cmd, err := cmd.ExecuteC()

require.Contains(t, err.Error(), "Try running \"coder login [url]\"")
})
t.Run("NoSessionAuthErrorHasHelperText", func(t *testing.T) {
t.Parallel()

client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
cmd, root := clitest.New(t, "users", "list")
clitest.SetupConfig(t, client, root)

cmd, err := cmd.ExecuteC()

require.Contains(t, err.Error(), "Try running \"coder login [url]\"")
})
}
3 changes: 1 addition & 2 deletions codersdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ func readBodyAsError(res *http.Response) error {
contentType := res.Header.Get("Content-Type")

var helper string
switch res.StatusCode {
case http.StatusUnauthorized:
if res.StatusCode == http.StatusUnauthorized {
helper = "Try running \"coder login [url]\"."
}

Expand Down
0