@@ -95,33 +95,50 @@ func TestSupportBundle(t *testing.T) {
95
95
clitest .SetupConfig (t , client , root )
96
96
err = inv .Run ()
97
97
require .NoError (t , err )
98
- assertBundleContents (t , path , secretValue )
98
+ assertBundleContents (t , path , true , true , [] string { secretValue } )
99
99
})
100
100
101
101
t .Run ("NoWorkspace" , func (t * testing.T ) {
102
102
t .Parallel ()
103
- client := coderdtest .New (t , nil )
103
+ var dc codersdk.DeploymentConfig
104
+ secretValue := uuid .NewString ()
105
+ seedSecretDeploymentOptions (t , & dc , secretValue )
106
+ client := coderdtest .New (t , & coderdtest.Options {
107
+ DeploymentValues : dc .Values ,
108
+ })
104
109
_ = coderdtest .CreateFirstUser (t , client )
105
- inv , root := clitest .New (t , "support" , "bundle" , "--yes" )
110
+
111
+ d := t .TempDir ()
112
+ path := filepath .Join (d , "bundle.zip" )
113
+ inv , root := clitest .New (t , "support" , "bundle" , "--output-file" , path , "--yes" )
106
114
//nolint: gocritic // requires owner privilege
107
115
clitest .SetupConfig (t , client , root )
108
116
err := inv .Run ()
109
- require .ErrorContains (t , err , "must specify workspace name" )
117
+ require .NoError (t , err )
118
+ assertBundleContents (t , path , false , false , []string {secretValue })
110
119
})
111
120
112
121
t .Run ("NoAgent" , func (t * testing.T ) {
113
122
t .Parallel ()
114
- client , db := coderdtest .NewWithDatabase (t , nil )
123
+ var dc codersdk.DeploymentConfig
124
+ secretValue := uuid .NewString ()
125
+ seedSecretDeploymentOptions (t , & dc , secretValue )
126
+ client , db := coderdtest .NewWithDatabase (t , & coderdtest.Options {
127
+ DeploymentValues : dc .Values ,
128
+ })
115
129
admin := coderdtest .CreateFirstUser (t , client )
116
130
r := dbfake .WorkspaceBuild (t , db , database.Workspace {
117
131
OrganizationID : admin .OrganizationID ,
118
132
OwnerID : admin .UserID ,
119
133
}).Do () // without agent!
120
- inv , root := clitest .New (t , "support" , "bundle" , r .Workspace .Name , "--yes" )
134
+ d := t .TempDir ()
135
+ path := filepath .Join (d , "bundle.zip" )
136
+ inv , root := clitest .New (t , "support" , "bundle" , r .Workspace .Name , "--output-file" , path , "--yes" )
121
137
//nolint: gocritic // requires owner privilege
122
138
clitest .SetupConfig (t , client , root )
123
139
err := inv .Run ()
124
- require .ErrorContains (t , err , "could not find agent" )
140
+ require .NoError (t , err )
141
+ assertBundleContents (t , path , true , false , []string {secretValue })
125
142
})
126
143
127
144
t .Run ("NoPrivilege" , func (t * testing.T ) {
@@ -140,7 +157,8 @@ func TestSupportBundle(t *testing.T) {
140
157
})
141
158
}
142
159
143
- func assertBundleContents (t * testing.T , path string , badValues ... string ) {
160
+ // nolint:revive // It's a control flag, but this is just a test.
161
+ func assertBundleContents (t * testing.T , path string , wantWorkspace bool , wantAgent bool , badValues []string ) {
144
162
t .Helper ()
145
163
r , err := zip .OpenReader (path )
146
164
require .NoError (t , err , "open zip file" )
@@ -173,64 +191,132 @@ func assertBundleContents(t *testing.T, path string, badValues ...string) {
173
191
case "network/netcheck.json" :
174
192
var v workspacesdk.AgentConnectionInfo
175
193
decodeJSONFromZip (t , f , & v )
194
+ if ! wantAgent || ! wantWorkspace {
195
+ require .Empty (t , v , "expected connection info to be empty" )
196
+ continue
197
+ }
176
198
require .NotEmpty (t , v , "connection info should not be empty" )
177
199
case "workspace/workspace.json" :
178
200
var v codersdk.Workspace
179
201
decodeJSONFromZip (t , f , & v )
202
+ if ! wantWorkspace {
203
+ require .Empty (t , v , "expected workspace to be empty" )
204
+ continue
205
+ }
180
206
require .NotEmpty (t , v , "workspace should not be empty" )
181
207
case "workspace/build_logs.txt" :
182
208
bs := readBytesFromZip (t , f )
209
+ if ! wantWorkspace || ! wantAgent {
210
+ require .Empty (t , bs , "expected workspace build logs to be empty" )
211
+ continue
212
+ }
183
213
require .Contains (t , string (bs ), "provision done" )
214
+ case "workspace/template.json" :
215
+ var v codersdk.Template
216
+ decodeJSONFromZip (t , f , & v )
217
+ if ! wantWorkspace {
218
+ require .Empty (t , v , "expected workspace template to be empty" )
219
+ continue
220
+ }
221
+ require .NotEmpty (t , v , "workspace template should not be empty" )
222
+ case "workspace/template_version.json" :
223
+ var v codersdk.TemplateVersion
224
+ decodeJSONFromZip (t , f , & v )
225
+ if ! wantWorkspace {
226
+ require .Empty (t , v , "expected workspace template version to be empty" )
227
+ continue
228
+ }
229
+ require .NotEmpty (t , v , "workspace template version should not be empty" )
230
+ case "workspace/parameters.json" :
231
+ var v []codersdk.WorkspaceBuildParameter
232
+ decodeJSONFromZip (t , f , & v )
233
+ if ! wantWorkspace {
234
+ require .Empty (t , v , "expected workspace parameters to be empty" )
235
+ continue
236
+ }
237
+ require .NotNil (t , v , "workspace parameters should not be nil" )
238
+ case "workspace/template_file.zip" :
239
+ bs := readBytesFromZip (t , f )
240
+ if ! wantWorkspace {
241
+ require .Empty (t , bs , "expected template file to be empty" )
242
+ continue
243
+ }
244
+ require .NotNil (t , bs , "template file should not be nil" )
184
245
case "agent/agent.json" :
185
246
var v codersdk.WorkspaceAgent
186
247
decodeJSONFromZip (t , f , & v )
248
+ if ! wantAgent {
249
+ require .Empty (t , v , "expected agent to be empty" )
250
+ continue
251
+ }
187
252
require .NotEmpty (t , v , "agent should not be empty" )
188
253
case "agent/listening_ports.json" :
189
254
var v codersdk.WorkspaceAgentListeningPortsResponse
190
255
decodeJSONFromZip (t , f , & v )
256
+ if ! wantAgent {
257
+ require .Empty (t , v , "expected agent listening ports to be empty" )
258
+ continue
259
+ }
191
260
require .NotEmpty (t , v , "agent listening ports should not be empty" )
192
261
case "agent/logs.txt" :
193
262
bs := readBytesFromZip (t , f )
263
+ if ! wantAgent {
264
+ require .Empty (t , bs , "expected agent logs to be empty" )
265
+ continue
266
+ }
194
267
require .NotEmpty (t , bs , "logs should not be empty" )
195
268
case "agent/agent_magicsock.html" :
196
269
bs := readBytesFromZip (t , f )
270
+ if ! wantAgent {
271
+ require .Empty (t , bs , "expected agent magicsock to be empty" )
272
+ continue
273
+ }
197
274
require .NotEmpty (t , bs , "agent magicsock should not be empty" )
198
275
case "agent/client_magicsock.html" :
199
276
bs := readBytesFromZip (t , f )
277
+ if ! wantAgent {
278
+ require .Empty (t , bs , "expected client magicsock to be empty" )
279
+ continue
280
+ }
200
281
require .NotEmpty (t , bs , "client magicsock should not be empty" )
201
282
case "agent/manifest.json" :
202
283
var v agentsdk.Manifest
203
284
decodeJSONFromZip (t , f , & v )
285
+ if ! wantAgent {
286
+ require .Empty (t , v , "expected agent manifest to be empty" )
287
+ continue
288
+ }
204
289
require .NotEmpty (t , v , "agent manifest should not be empty" )
205
290
case "agent/peer_diagnostics.json" :
206
291
var v * tailnet.PeerDiagnostics
207
292
decodeJSONFromZip (t , f , & v )
293
+ if ! wantAgent {
294
+ require .Empty (t , v , "expected peer diagnostics to be empty" )
295
+ continue
296
+ }
208
297
require .NotEmpty (t , v , "peer diagnostics should not be empty" )
209
298
case "agent/ping_result.json" :
210
299
var v * ipnstate.PingResult
211
300
decodeJSONFromZip (t , f , & v )
301
+ if ! wantAgent {
302
+ require .Empty (t , v , "expected ping result to be empty" )
303
+ continue
304
+ }
212
305
require .NotEmpty (t , v , "ping result should not be empty" )
213
306
case "agent/prometheus.txt" :
214
307
bs := readBytesFromZip (t , f )
308
+ if ! wantAgent {
309
+ require .Empty (t , bs , "expected agent prometheus metrics to be empty" )
310
+ continue
311
+ }
215
312
require .NotEmpty (t , bs , "agent prometheus metrics should not be empty" )
216
313
case "agent/startup_logs.txt" :
217
314
bs := readBytesFromZip (t , f )
315
+ if ! wantAgent {
316
+ require .Empty (t , bs , "expected agent startup logs to be empty" )
317
+ continue
318
+ }
218
319
require .Contains (t , string (bs ), "started up" )
219
- case "workspace/template.json" :
220
- var v codersdk.Template
221
- decodeJSONFromZip (t , f , & v )
222
- require .NotEmpty (t , v , "workspace template should not be empty" )
223
- case "workspace/template_version.json" :
224
- var v codersdk.TemplateVersion
225
- decodeJSONFromZip (t , f , & v )
226
- require .NotEmpty (t , v , "workspace template version should not be empty" )
227
- case "workspace/parameters.json" :
228
- var v []codersdk.WorkspaceBuildParameter
229
- decodeJSONFromZip (t , f , & v )
230
- require .NotNil (t , v , "workspace parameters should not be nil" )
231
- case "workspace/template_file.zip" :
232
- bs := readBytesFromZip (t , f )
233
- require .NotNil (t , bs , "template file should not be nil" )
234
320
case "logs.txt" :
235
321
bs := readBytesFromZip (t , f )
236
322
require .NotEmpty (t , bs , "logs should not be empty" )
0 commit comments