File tree
9 files changed
+115
-25
lines changed- src
- main
- kotlin/com/coder/gateway
- cli
- settings
- resources/messages
- test
- fixtures/outputs
- kotlin/com/coder/gateway
- cli
- settings
9 files changed
+115
-25
lines changedLines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
15 | 15 |
| |
16 | 16 |
| |
17 | 17 |
| |
| 18 | + | |
| 19 | + | |
18 | 20 |
| |
19 | 21 |
| |
20 | 22 |
| |
|
Lines changed: 7 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
| 48 | + | |
48 | 49 |
| |
49 | 50 |
| |
50 | 51 |
| |
| |||
239 | 240 |
| |
240 | 241 |
| |
241 | 242 |
| |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
242 | 248 |
| |
243 | 249 |
| |
244 | 250 |
| |
| |||
286 | 292 |
| |
287 | 293 |
| |
288 | 294 |
| |
289 |
| - | |
| 295 | + | |
290 | 296 |
| |
291 | 297 |
| |
292 | 298 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
139 | 139 |
| |
140 | 140 |
| |
141 | 141 |
| |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 |
| |
143 | 148 |
| |
144 | 149 |
| |
|
Lines changed: 9 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
262 | 262 |
| |
263 | 263 |
| |
264 | 264 |
| |
265 |
| - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
266 | 270 |
| |
267 | 271 |
| |
268 | 272 |
| |
| |||
368 | 372 |
| |
369 | 373 |
| |
370 | 374 |
| |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
371 | 379 |
| |
372 | 380 |
| |
373 | 381 |
| |
| |||
453 | 461 |
| |
454 | 462 |
| |
455 | 463 |
| |
456 |
| - | |
457 | 464 |
| |
458 | 465 |
| |
459 | 466 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
82 | 82 |
| |
83 | 83 |
| |
84 | 84 |
| |
| 85 | + | |
| 86 | + | |
85 | 87 |
| |
86 | 88 |
| |
87 | 89 |
| |
| |||
175 | 177 |
| |
176 | 178 |
| |
177 | 179 |
| |
| 180 | + | |
| 181 | + | |
| 182 | + | |
178 | 183 |
| |
179 | 184 |
| |
180 | 185 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
148 | 148 |
| |
149 | 149 |
| |
150 | 150 |
| |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + |
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + |
Lines changed: 64 additions & 21 deletions
@@ -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
-
F438
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,53 @@ 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(
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
+ ),
347
372
SSHTest(
348
373
listOf("extra"),
349
374
null,
350
375
"extra-config",
351
376
"blank",
352
377
extraConfig = extraConfig,
353
- features = Features(false, true),
354
378
),
355
379
SSHTest(
356
380
listOf("extra"),
357
381
null,
358
382
"extra-config",
359
383
"blank",
360
384
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"),
362
392
),
363
393
)
364
394
@@ -372,6 +402,7 @@ internal class CoderCLIManagerTest {
372
402
dataDirectory = tmpdir.resolve("configure-ssh").toString(),
373
403
headerCommand = it.headerCommand,
374
404
sshConfigOptions = it.extraConfig,
405
+ sshLogDirectory = it.sshLogDirectory?.toString() ?: "",
375
406
),
376
407
sshConfigPath = tmpdir.resolve(it.input + "_to_" + it.output + ".conf"),
377
408
env = it.env,
@@ -395,12 +426,24 @@ internal class CoderCLIManagerTest {
395
426
.replace(newlineRe, System.lineSeparator())
396
427
.replace("/tmp/coder-gateway/test.coder.invalid/config", escape(coderConfigPath.toString()))
397
428
.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
+ }
398
436
399
437
// Add workspaces.
400
438
ccm.configSsh(it.workspaces.toSet(), it.features)
401
439
402
440
assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
403
441
442
+ // SSH log directory should have been created.
443
+ if (it.sshLogDirectory != null) {
444
+ assertTrue(it.sshLogDirectory.toFile().exists())
445
+ }
446
+
404
447
// Remove configuration.
405
448
ccm.configSsh(emptySet(), it.features)
406
449
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
302 | 302 |
| |
303 | 303 |
| |
304 | 304 |
| |
305 |
| - | |
| 305 | + | |
306 | 306 |
| |
307 | 307 |
| |
308 | 308 |
| |
| |||
386 | 386 |
| |
387 | 387 |
| |
388 | 388 |
| |
| 389 | + | |
389 | 390 |
| |
390 | 391 |
| |
391 | 392 |
| |
| |||
399 | 400 |
| |
400 | 401 |
| |
401 | 402 |
| |
| 403 | + | |
402 | 404 |
| |
403 | 405 |
|
0 commit comments