@@ -100,7 +100,7 @@ func TestMain(m *testing.M) {
100
100
func Test_checkVersions (t * testing.T ) {
101
101
t .Parallel ()
102
102
103
- t .Run ("CustomInstallMessage " , func (t * testing.T ) {
103
+ t .Run ("CustomUpgradeMessage " , func (t * testing.T ) {
104
104
t .Parallel ()
105
105
106
106
var (
@@ -141,4 +141,43 @@ func Test_checkVersions(t *testing.T) {
141
141
expectedOutput := fmt .Sprintln (pretty .Sprint (cliui .DefaultStyles .Warn , fmtOutput ))
142
142
require .Equal (t , expectedOutput , buf .String ())
143
143
})
144
+
145
+ t .Run ("DefaultUpgradeMessage" , func (t * testing.T ) {
146
+ t .Parallel ()
147
+
148
+ srv := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , r * http.Request ) {
149
+ httpapi .Write (r .Context (), rw , http .StatusOK , codersdk.BuildInfoResponse {
150
+ ExternalURL : buildinfo .ExternalURL (),
151
+ // Provide a version that will not match
152
+ Version : "v1.0.0" ,
153
+ AgentAPIVersion : coderd .AgentAPIVersionREST ,
154
+ // does not matter what the url is
155
+ DashboardURL : "https://example.com" ,
156
+ WorkspaceProxy : false ,
157
+ UpgradeMessage : "" ,
158
+ })
159
+ }))
160
+ defer srv .Close ()
161
+ surl , err := url .Parse (srv .URL )
162
+ require .NoError (t , err )
163
+
164
+ client := codersdk .New (surl )
165
+
166
+ r := & RootCmd {}
167
+
168
+ cmd , err := r .Command (nil )
169
+ require .NoError (t , err )
170
+
171
+ var buf bytes.Buffer
172
+ inv := cmd .Invoke ()
173
+ inv .Stderr = & buf
174
+
175
+ err = r .checkVersions (inv , client , "v2.0.0" )
176
+ require .NoError (t , err )
177
+
178
+ fmtOutput := fmt .Sprintf ("version mismatch: client v2.0.0, server 1.0.0\n %s" , defaultUpgradeMessage ())
179
+ expectedOutput := fmt .Sprintln (pretty .Sprint (cliui .DefaultStyles .Warn , fmtOutput ))
180
+ require .Equal (t , expectedOutput , buf .String ())
181
+ })
182
+
144
183
}
0 commit comments