@@ -3,16 +3,21 @@ package cli
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
+ "net/http"
7
+ "net/http/httptest"
8
+ "net/url"
6
9
"os"
7
10
"runtime"
8
11
"testing"
9
12
10
13
"github.com/stretchr/testify/require"
11
14
"go.uber.org/goleak"
12
15
13
- "github.com/coder/coder/v2/cli/clibase "
16
+ "github.com/coder/coder/v2/buildinfo "
14
17
"github.com/coder/coder/v2/cli/cliui"
15
- "github.com/coder/coder/v2/coderd/coderdtest"
18
+ "github.com/coder/coder/v2/coderd"
19
+ "github.com/coder/coder/v2/coderd/httpapi"
20
+ "github.com/coder/coder/v2/codersdk"
16
21
"github.com/coder/pretty"
17
22
)
18
23
@@ -100,18 +105,25 @@ func Test_checkVersions(t *testing.T) {
100
105
101
106
var (
102
107
expectedUpgradeMessage = "My custom upgrade message"
103
- dv = coderdtest .DeploymentValues (t )
104
108
)
105
- dv .CLIUpgradeMessage = clibase .String (expectedUpgradeMessage )
106
109
107
- ownerClient := coderdtest .New (t , & coderdtest.Options {
108
- DeploymentValues : dv ,
109
- })
110
- owner := coderdtest .CreateFirstUser (t , ownerClient )
110
+ srv := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
111
+ httpapi .Write (r .Context (), rw , http .StatusOK , codersdk.BuildInfoResponse {
112
+ ExternalURL : buildinfo .ExternalURL (),
113
+ // Provide a version that will not match
114
+ Version : "v1.0.0" ,
115
+ AgentAPIVersion : coderd .AgentAPIVersionREST ,
116
+ // does not matter what the url is
117
+ DashboardURL : "https://example.com" ,
118
+ WorkspaceProxy : false ,
119
+ UpgradeMessage : expectedUpgradeMessage ,
120
+ })
121
+ }))
122
+ defer srv .Close ()
123
+ surl , err := url .Parse (srv .URL )
124
+ require .NoError (t , err )
111
125
112
- // Create an unprivileged user to ensure the message can be printed
113
- // to any Coder user.
114
- memberClient , _ := coderdtest .CreateAnotherUser (t , ownerClient , owner .OrganizationID )
126
+ client := codersdk .New (surl )
115
127
116
128
r := & RootCmd {}
117
129
@@ -122,10 +134,11 @@ func Test_checkVersions(t *testing.T) {
122
134
inv := cmd .Invoke ()
123
135
inv .Stderr = & buf
124
136
125
- err = r .checkVersions (inv , memberClient , true )
137
+ err = r .checkVersions (inv , client , "v2.0.0" )
126
138
require .NoError (t , err )
127
139
128
- expectedOutput := fmt .Sprintln (pretty .Sprint (cliui .DefaultStyles .Warn , expectedUpgradeMessage ))
140
+ fmtOutput := fmt .Sprintf ("version mismatch: client v2.0.0, server 1.0.0\n %s" , expectedUpgradeMessage )
141
+ expectedOutput := fmt .Sprintln (pretty .Sprint (cliui .DefaultStyles .Warn , fmtOutput ))
129
142
require .Equal (t , expectedOutput , buf .String ())
130
143
})
131
144
}
0 commit comments