mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
fix: enrich the notLoggedInMessage
error message with the full path to the coder (#17715)
--------- Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package cli_test
|
package cli_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
@ -89,10 +90,14 @@ func TestLogout(t *testing.T) {
|
|||||||
logout.Stdin = pty.Input()
|
logout.Stdin = pty.Input()
|
||||||
logout.Stdout = pty.Output()
|
logout.Stdout = pty.Output()
|
||||||
|
|
||||||
|
executable, err := os.Executable()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotEqual(t, "", executable)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(logoutChan)
|
defer close(logoutChan)
|
||||||
err := logout.Run()
|
err = logout.Run()
|
||||||
assert.ErrorContains(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
|
assert.Contains(t, err.Error(), fmt.Sprintf("Try logging in using '%s login <url>'.", executable))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
<-logoutChan
|
<-logoutChan
|
||||||
|
@ -72,7 +72,7 @@ const (
|
|||||||
varDisableDirect = "disable-direct-connections"
|
varDisableDirect = "disable-direct-connections"
|
||||||
varDisableNetworkTelemetry = "disable-network-telemetry"
|
varDisableNetworkTelemetry = "disable-network-telemetry"
|
||||||
|
|
||||||
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
|
notLoggedInMessage = "You are not logged in. Try logging in using '%s login <url>'."
|
||||||
|
|
||||||
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
|
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
|
||||||
envNoFeatureWarning = "CODER_NO_FEATURE_WARNING"
|
envNoFeatureWarning = "CODER_NO_FEATURE_WARNING"
|
||||||
@ -534,7 +534,11 @@ func (r *RootCmd) InitClient(client *codersdk.Client) serpent.MiddlewareFunc {
|
|||||||
rawURL, err := conf.URL().Read()
|
rawURL, err := conf.URL().Read()
|
||||||
// If the configuration files are absent, the user is logged out
|
// If the configuration files are absent, the user is logged out
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return xerrors.New(notLoggedInMessage)
|
binPath, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
binPath = "coder"
|
||||||
|
}
|
||||||
|
return xerrors.Errorf(notLoggedInMessage, binPath)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -69,9 +71,12 @@ func TestUserList(t *testing.T) {
|
|||||||
t.Run("NoURLFileErrorHasHelperText", func(t *testing.T) {
|
t.Run("NoURLFileErrorHasHelperText", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
executable, err := os.Executable()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
inv, _ := clitest.New(t, "users", "list")
|
inv, _ := clitest.New(t, "users", "list")
|
||||||
err := inv.Run()
|
err = inv.Run()
|
||||||
require.Contains(t, err.Error(), "Try logging in using 'coder login <url>'.")
|
require.Contains(t, err.Error(), fmt.Sprintf("Try logging in using '%s login <url>'.", executable))
|
||||||
})
|
})
|
||||||
t.Run("SessionAuthErrorHasHelperText", func(t *testing.T) {
|
t.Run("SessionAuthErrorHasHelperText", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
Reference in New Issue
Block a user