@@ -295,9 +295,14 @@ internal class CoderCLIManagerTest {
295295 val remove : String ,
296296 val headerCommand : String = " " ,
297297 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+ ),
299303 val extraConfig : String = " " ,
300304 val env : Environment = Environment (),
305+ val sshLogDirectory : Path ? = null ,
301306 )
302307
303308 @Test
@@ -309,27 +314,26 @@ internal class CoderCLIManagerTest {
309314 ).joinToString(System .lineSeparator())
310315 val tests =
311316 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" ),
325330 if (getOS() == OS .WINDOWS ) {
326331 SSHTest (
327332 listOf (" header" ),
328333 null ,
329334 " header-command-windows" ,
330335 " blank" ,
331336 """ "C:\Program Files\My Header Command\HeaderCommand.exe" --url="%CODER_URL%" --test="foo bar"""" ,
332- features = Features (false , true ),
333337 )
334338 } else {
335339 SSHTest (
@@ -338,27 +342,53 @@ internal class CoderCLIManagerTest {
338342 " header-command" ,
339343 " blank" ,
340344 " my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" ,
341- features = Features (false , true ),
342345 )
343346 },
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 (
348+ listOf (" foo" ),
349+ null ,
350+ " disable-autostart" ,
351+ " blank" ,
352+ " " ,
353+ true ,
354+ Features (
355+ disableAutostart = true ,
356+ reportWorkspaceUsage = true ,
357+ ),
358+ ),
359+ SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , " " ),
360+ SSHTest (
361+ listOf (" foo" ),
362+ null ,
363+ " no-report-usage" ,
364+ " blank" ,
365+ " " ,
366+ true ,
367+ Features (
368+ disableAutostart = false ,
369+ reportWorkspaceUsage = false ,
370+ ),
371+ ),
347372 SSHTest (
348373 listOf (" extra" ),
349374 null ,
350375 " extra-config" ,
351376 " blank" ,
352377 extraConfig = extraConfig,
353- features = Features (false , true ),
354378 ),
355379 SSHTest (
356380 listOf (" extra" ),
357381 null ,
358382 " extra-config" ,
359383 " blank" ,
360384 env = Environment (mapOf (CODER_SSH_CONFIG_OPTIONS to extraConfig)),
361- features = Features (false , true ),
385+ ),
386+ SSHTest (
387+ listOf (" foo" ),
388+ null ,
389+ " log-dir" ,
390+ " blank" ,
391+ sshLogDirectory = tmpdir.resolve(" ssh-logs" ),
362392 ),
363393 )
364394
@@ -372,6 +402,7 @@ internal class CoderCLIManagerTest {
372402 dataDirectory = tmpdir.resolve(" configure-ssh" ).toString(),
373403 headerCommand = it.headerCommand,
374404 sshConfigOptions = it.extraConfig,
405+ sshLogDirectory = it.sshLogDirectory?.toString() ? : " " ,
375406 ),
376407 sshConfigPath = tmpdir.resolve(it.input + " _to_" + it.output + " .conf" ),
377408 env = it.env,
@@ -395,12 +426,24 @@ internal class CoderCLIManagerTest {
395426 .replace(newlineRe, System .lineSeparator())
396427 .replace(" /tmp/coder-gateway/test.coder.invalid/config" , escape(coderConfigPath.toString()))
397428 .replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
429+ .let { conf ->
430+ if (it.sshLogDirectory != null ) {
431+ conf.replace(" /tmp/coder-gateway/test.coder.invalid/logs" , it.sshLogDirectory.toString())
432+ } else {
433+ conf
434+ }
435+ }
398436
399437 // Add workspaces.
400438 ccm.configSsh(it.workspaces.toSet(), it.features)
401439
402440 assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
403441
442+ // SSH log directory should have been created.
443+ if (it.sshLogDirectory != null ) {
444+ assertTrue(it.sshLogDirectory.toFile().exists())
445+ }
446+
404447 // Remove configuration.
405448 ccm.configSsh(emptySet(), it.features)
406449
0 commit comments