Skip to content

Commit 590af3d

Browse files
committed
chore: remove middleware to request version and entitlement warnings
This cleans up `root.go` a bit, adds tests for middleware HTTP transport functions, and removes two HTTP requests we always always performed previously when executing *any* client command. It should improve CLI performance (especially for users with higher latency).
1 parent 5738a03 commit 590af3d

File tree

17 files changed

+444
-425
lines changed

17 files changed

+444
-425
lines changed

cli/login.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"github.com/coder/pretty"
2020

21-
"github.com/coder/coder/v2/buildinfo"
2221
"github.com/coder/coder/v2/cli/cliui"
2322
"github.com/coder/coder/v2/coderd/userpassword"
2423
"github.com/coder/coder/v2/codersdk"
@@ -180,21 +179,11 @@ func (r *RootCmd) login() *serpent.Command {
180179
serverURL.Scheme = "https"
181180
}
182181

183-
client, err := r.createUnauthenticatedClient(ctx, serverURL)
182+
client, err := r.createUnauthenticatedClient(ctx, serverURL, inv)
184183
if err != nil {
185184
return err
186185
}
187186

188-
// Try to check the version of the server prior to logging in.
189-
// It may be useful to warn the user if they are trying to login
190-
// on a very old client.
191-
err = r.checkVersions(inv, client, buildinfo.Version())
192-
if err != nil {
193-
// Checking versions isn't a fatal error so we print a warning
194-
// and proceed.
195-
_, _ = fmt.Fprintln(inv.Stderr, pretty.Sprint(cliui.DefaultStyles.Warn, err.Error()))
196-
}
197-
198187
hasFirstUser, err := client.HasFirstUser(ctx)
199188
if err != nil {
200189
return xerrors.Errorf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser? Error - has initial user: %w", serverURL.String(), err)

cli/logout_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,33 +97,6 @@ func TestLogout(t *testing.T) {
9797

9898
<-logoutChan
9999
})
100-
t.Run("NoSessionFile", func(t *testing.T) {
101-
t.Parallel()
102-
103-
pty := ptytest.New(t)
104-
config := login(t, pty)
105-
106-
// Ensure session files exist.
107-
require.FileExists(t, string(config.URL()))
108-
require.FileExists(t, string(config.Session()))
109-
110-
err := os.Remove(string(config.Session()))
111-
require.NoError(t, err)
112-
113-
logoutChan := make(chan struct{})
114-
logout, _ := clitest.New(t, "logout", "--global-config", string(config))
115-
116-
logout.Stdin = pty.Input()
117-
logout.Stdout = pty.Output()
118-
119-
go func() {
120-
defer close(logoutChan)
121-
err = logout.Run()
122-
assert.ErrorContains(t, err, "You are not logged in. Try logging in using 'coder login'.")
123-
}()
124-
125-
<-logoutChan
126-
})
127100
t.Run("CannotDeleteFiles", func(t *testing.T) {
128101
t.Parallel()
129102

0 commit comments

Comments
 (0)