@@ -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,7 @@ func TestSupportBundle(t *testing.T) {
140
157
})
141
158
}
142
159
143
- func assertBundleContents (t * testing.T , path string , badValues ... string ) {
160
+ func assertBundleContents (t * testing.T , path string , wantWorkspace bool , wantAgent bool , badValues [] string ) {
144
161
t .Helper ()
145
162
r , err := zip .OpenReader (path )
146
163
require .NoError (t , err , "open zip file" )
@@ -173,64 +190,132 @@ func assertBundleContents(t *testing.T, path string, badValues ...string) {
173
190
case "network/netcheck.json" :
174
191
var v workspacesdk.AgentConnectionInfo
175
192
decodeJSONFromZip (t , f , & v )
193
+ if ! wantAgent || ! wantWorkspace {
194
+ require .Empty (t , v , "expected connection info to be empty" )
195
+ continue
196
+ }
176
197
require .NotEmpty (t , v , "connection info should not be empty" )
177
198
case "workspace/workspace.json" :
178
199
var v codersdk.Workspace
179
200
decodeJSONFromZip (t , f , & v )
201
+ if ! wantWorkspace {
202
+ require .Empty (t , v , "expected workspace to be empty" )
203
+ continue
204
+ }
180
205
require .NotEmpty (t , v , "workspace should not be empty" )
181
206
case "workspace/build_logs.txt" :
182
207
bs := readBytesFromZip (t , f )
208
+ if ! wantWorkspace || ! wantAgent {
209
+ require .Empty (t , bs , "expected workspace build logs to be empty" )
210
+ continue
211
+ }
183
212
require .Contains (t , string (bs ), "provision done" )
213
+ case "workspace/template.json" :
214
+ var v codersdk.Template
215
+ decodeJSONFromZip (t , f , & v )
216
+ if ! wantWorkspace {
217
+ require .Empty (t , v , "expected workspace template to be empty" )
218
+ continue
219
+ }
220
+ require .NotEmpty (t , v , "workspace template should not be empty" )
221
+ case "workspace/template_version.json" :
222
+ var v codersdk.TemplateVersion
223
+ decodeJSONFromZip (t , f , & v )
224
+ if ! wantWorkspace {
225
+ require .Empty (t , v , "expected workspace template version to be empty" )
226
+ continue
227
+ }
228
+ require .NotEmpty (t , v , "workspace template version should not be empty" )
229
+ case "workspace/parameters.json" :
230
+ var v []codersdk.WorkspaceBuildParameter
231
+ decodeJSONFromZip (t , f , & v )
232
+ if ! wantWorkspace {
233
+ require .Empty (t , v , "expected workspace parameters to be empty" )
234
+ continue
235
+ }
236
+ require .NotNil (t , v , "workspace parameters should not be nil" )
237
+ case "workspace/template_file.zip" :
238
+ bs := readBytesFromZip (t , f )
239
+ if ! wantWorkspace {
240
+ require .Empty (t , bs , "expected template file to be empty" )
241
+ continue
242
+ }
243
+ require .NotNil (t , bs , "template file should not be nil" )
184
244
case "agent/agent.json" :
185
245
var v codersdk.WorkspaceAgent
186
246
decodeJSONFromZip (t , f , & v )
247
+ if ! wantAgent {
248
+ require .Empty (t , v , "expected agent to be empty" )
249
+ continue
250
+ }
187
251
require .NotEmpty (t , v , "agent should not be empty" )
188
252
case "agent/listening_ports.json" :
189
253
var v codersdk.WorkspaceAgentListeningPortsResponse
190
254
decodeJSONFromZip (t , f , & v )
255
+ if ! wantAgent {
256
+ require .Empty (t , v , "expected agent listening ports to be empty" )
257
+ continue
258
+ }
191
259
require .NotEmpty (t , v , "agent listening ports should not be empty" )
192
260
case "agent/logs.txt" :
193
261
bs := readBytesFromZip (t , f )
262
+ if ! wantAgent {
263
+ require .Empty (t , bs , "expected agent logs to be empty" )
264
+ continue
265
+ }
194
266
require .NotEmpty (t , bs , "logs should not be empty" )
195
267
case "agent/agent_magicsock.html" :
196
268
bs := readBytesFromZip (t , f )
269
+ if ! wantAgent {
270
+ require .Empty (t , bs , "expected agent magicsock to be empty" )
271
+ continue
272
+ }
197
273
require .NotEmpty (t , bs , "agent magicsock should not be empty" )
198
274
case "agent/client_magicsock.html" :
199
275
bs := readBytesFromZip (t , f )
276
+ if ! wantAgent {
277
+ require .Empty (t , bs , "expected client magicsock to be empty" )
278
+ continue
279
+ }
200
280
require .NotEmpty (t , bs , "client magicsock should not be empty" )
201
281
case "agent/manifest.json" :
202
282
var v agentsdk.Manifest
203
283
decodeJSONFromZip (t , f , & v )
284
+ if ! wantAgent {
285
+ require .Empty (t , v , "expected agent manifest to be empty" )
286
+ continue
287
+ }
204
288
require .NotEmpty (t , v , "agent manifest should not be empty" )
205
289
case "agent/peer_diagnostics.json" :
206
290
var v * tailnet.PeerDiagnostics
207
291
decodeJSONFromZip (t , f , & v )
292
+ if ! wantAgent {
293
+ require .Empty (t , v , "expected peer diagnostics to be empty" )
294
+ continue
295
+ }
208
296
require .NotEmpty (t , v , "peer diagnostics should not be empty" )
209
297
case "agent/ping_result.json" :
210
298
var v * ipnstate.PingResult
211
299
decodeJSONFromZip (t , f , & v )
300
+ if ! wantAgent {
301
+ require .Empty (t , v , "expected ping result to be empty" )
302
+ continue
303
+ }
212
304
require .NotEmpty (t , v , "ping result should not be empty" )
213
305
case "agent/prometheus.txt" :
214
306
bs := readBytesFromZip (t , f )
307
+ if ! wantAgent {
308
+ require .Empty (t , bs , "expected agent prometheus metrics to be empty" )
309
+ continue
310
+ }
215
311
require .NotEmpty (t , bs , "agent prometheus metrics should not be empty" )
216
312
case "agent/startup_logs.txt" :
217
313
bs := readBytesFromZip (t , f )
314
+ if ! wantAgent {
315
+ require .Empty (t , bs , "expected agent startup logs to be empty" )
316
+ continue
317
+ }
218
318
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
319
case "logs.txt" :
235
320
bs := readBytesFromZip (t , f )
236
321
require .NotEmpty (t , bs , "logs should not be empty" )
0 commit comments