@@ -295,9 +295,14 @@ internal class CoderCLIManagerTest {
295
295
val remove : String ,
296
296
val headerCommand : String = " " ,
297
297
val disableAutostart : Boolean = false ,
298
- val features : Features = Features (),
298
+ // Default to the most common feature settings.
299
+ val features : Features = Features (
300
+ disableAutostart = false,
301
+ reportWorkspaceUsage = true,
302
+ ),
299
303
val extraConfig : String = " " ,
300
304
val env : Environment = Environment (),
305
+ val sshLogDirectory : Path ? = null ,
301
306
)
302
307
303
308
@Test
@@ -309,27 +314,26 @@ internal class CoderCLIManagerTest {
309
314
).joinToString(System .lineSeparator())
310
315
val tests =
311
316
listOf (
312
- SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" , features = Features ( false , true ) ),
313
- SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" , features = Features ( false , true ) ),
314
- SSHTest (listOf (" foo-bar" ), " blank" , " append-blank" , " blank" , features = Features ( false , true ) ),
315
- SSHTest (listOf (" foo-bar" ), " blank-newlines" , " append-blank-newlines" , " blank" , features = Features ( false , true ) ),
316
- SSHTest (listOf (" foo-bar" ), " existing-end" , " replace-end" , " no-blocks" , features = Features ( false , true ) ),
317
- SSHTest (listOf (" foo-bar" ), " existing-end-no-newline" , " replace-end-no-newline" , " no-blocks" , features = Features ( false , true ) ),
318
- SSHTest (listOf (" foo-bar" ), " existing-middle" , " replace-middle" , " no-blocks" , features = Features ( false , true ) ),
319
- SSHTest (listOf (" foo-bar" ), " existing-middle-and-unrelated" , " replace-middle-ignore-unrelated" , " no-related-blocks" , features = Features ( false , true ) ),
320
- SSHTest (listOf (" foo-bar" ), " existing-only" , " replace-only" , " blank" , features = Features ( false , true ) ),
321
- SSHTest (listOf (" foo-bar" ), " existing-start" , " replace-start" , " no-blocks" , features = Features ( false , true ) ),
322
- SSHTest (listOf (" foo-bar" ), " no-blocks" , " append-no-blocks" , " no-blocks" , features = Features ( false , true ) ),
323
- SSHTest (listOf (" foo-bar" ), " no-related-blocks" , " append-no-related-blocks" , " no-related-blocks" , features = Features ( false , true ) ),
324
- SSHTest (listOf (" foo-bar" ), " no-newline" , " append-no-newline" , " no-blocks" , features = Features ( false , true ) ),
317
+ SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" ),
318
+ SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" ),
319
+ SSHTest (listOf (" foo-bar" ), " blank" , " append-blank" , " blank" ),
320
+ SSHTest (listOf (" foo-bar" ), " blank-newlines" , " append-blank-newlines" , " blank" ),
321
+ SSHTest (listOf (" foo-bar" ), " existing-end" , " replace-end" , " no-blocks" ),
322
+ SSHTest (listOf (" foo-bar" ), " existing-end-no-newline" , " replace-end-no-newline" , " no-blocks" ),
323
+ SSHTest (listOf (" foo-bar" ), " existing-middle" , " replace-middle" , " no-blocks" ),
324
+ SSHTest (listOf (" foo-bar" ), " existing-middle-and-unrelated" , " replace-middle-ignore-unrelated" , " no-related-blocks" ),
325
+ SSHTest (listOf (" foo-bar" ), " existing-only" , " replace-only" , " blank" ),
326
+ SSHTest (listOf (" foo-bar" ), " existing-start" , " replace-start" , " no-blocks" ),
327
+ SSHTest (listOf (" foo-bar" ), " no-blocks" , " append-no-blocks" , " no-blocks" ),
328
+ SSHTest (listOf (" foo-bar" ), " no-related-blocks" , " append-no-related-blocks" , " no-related-blocks" ),
329
+ SSHTest (listOf (" foo-bar" ), " no-newline" , " append-no-newline" , " no-blocks" ),
325
330
if (getOS() == OS .WINDOWS ) {
326
331
SSHTest (
327
332
listOf (" header" ),
328
333
null ,
329
334
" header-command-windows" ,
330
335
" blank" ,
331
336
""" "C:\Program Files\My Header Command\HeaderCommand.exe" --url="%CODER_URL%" --test="foo bar"""" ,
332
- features = Features (false , true ),
333
337
)
334
338
} else {
335
339
SSHTest (
@@ -338,27 +342,37 @@ internal class CoderCLIManagerTest {
338
342
" header-command" ,
339
343
" blank" ,
340
344
" my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" ,
341
- features = Features (false , true ),
342
345
)
343
346
},
344
- SSHTest (listOf (" foo" ), null , " disable-autostart" , " blank" , " " , true , Features (true , true )),
345
- SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , " " , true , Features (false , true )),
346
- SSHTest (listOf (" foo" ), null , " no-report-usage" , " blank" , " " , true , Features (false , false )),
347
+ SSHTest (listOf (" foo" ), null , " disable-autostart" , " blank" , " " , true , Features (
348
+ disableAutostart = true ,
349
+ reportWorkspaceUsage = true
350
+ )),
351
+ SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , " " ),
352
+ SSHTest (listOf (" foo" ), null , " no-report-usage" , " blank" , " " , true , Features (
353
+ disableAutostart = false ,
354
+ reportWorkspaceUsage = false
355
+ )),
347
356
SSHTest (
348
357
listOf (" extra" ),
349
358
null ,
350
359
" extra-config" ,
351
360
" blank" ,
352
361
extraConfig = extraConfig,
353
- features = Features (false , true ),
354
362
),
355
363
SSHTest (
356
364
listOf (" extra" ),
357
365
null ,
358
366
" extra-config" ,
359
367
" blank" ,
360
368
env = Environment (mapOf (CODER_SSH_CONFIG_OPTIONS to extraConfig)),
361
- features = Features (false , true ),
369
+ ),
370
+ SSHTest (
371
+ listOf (" foo" ),
372
+ null ,
373
+ " log-dir" ,
374
+ " blank" ,
375
+ sshLogDirectory = tmpdir.resolve(" ssh-logs" ),
362
376
),
363
377
)
364
378
@@ -372,6 +386,7 @@ internal class CoderCLIManagerTest {
372
386
dataDirectory = tmpdir.resolve(" configure-ssh" ).toString(),
373
387
headerCommand = it.headerCommand,
374
388
sshConfigOptions = it.extraConfig,
389
+ sshLogDirectory = it.sshLogDirectory?.toString() ? : " " ,
375
390
),
376
391
sshConfigPath = tmpdir.resolve(it.input + " _to_" + it.output + " .conf" ),
377
392
env = it.env,
@@ -395,12 +410,24 @@ internal class CoderCLIManagerTest {
395
410
.replace(newlineRe, System .lineSeparator())
396
411
.replace(" /tmp/coder-gateway/test.coder.invalid/config" , escape(coderConfigPath.toString()))
397
412
.replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
413
+ .let { conf ->
414
+ if (it.sshLogDirectory != null ) {
415
+ conf.replace(" /tmp/coder-gateway/test.coder.invalid/logs" , it.sshLogDirectory.toString())
416
+ } else {
417
+ conf
418
+ }
419
+ }
398
420
399
421
// Add workspaces.
400
422
ccm.configSsh(it.workspaces.toSet(), it.features)
401
423
402
424
assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
403
425
426
+ // SSH log directory should have been created.
427
+ if (it.sshLogDirectory != null ) {
428
+ assertTrue(it.sshLogDirectory.toFile().exists())
429
+ }
430
+
404
431
// Remove configuration.
405
432
ccm.configSsh(emptySet(), it.features)
406
433
0 commit comments