@@ -3,8 +3,8 @@ package com.coder.gateway.cli
3
3
import com.coder.gateway.cli.ex.MissingVersionException
4
4
import com.coder.gateway.cli.ex.ResponseException
5
5
import com.coder.gateway.cli.ex.SSHConfigFormatException
6
- import com.coder.gateway.settings.CoderSettingsState
7
6
import com.coder.gateway.settings.CoderSettings
7
+ import com.coder.gateway.settings.CoderSettingsState
8
8
import com.coder.gateway.util.InvalidVersionException
9
9
import com.coder.gateway.util.OS
10
10
import com.coder.gateway.util.SemVer
@@ -238,34 +238,38 @@ internal class CoderCLIManagerTest {
238
238
val input : String? ,
239
239
val output : String ,
240
240
val remove : String ,
241
- val headerCommand : String? ,
241
+ val headerCommand : String = " " ,
242
242
val disableAutostart : Boolean = false ,
243
- val features : Features ? = null ,
243
+ val features : Features = Features (),
244
+ val extraConfig : String = " " ,
244
245
)
245
246
246
247
@Test
247
248
fun testConfigureSSH () {
248
249
val tests = listOf (
249
- SSHTest (listOf (" foo" , " bar" ), null ," multiple-workspaces" , " blank" , null ),
250
- SSHTest (listOf (" foo" , " bar" ), null ," multiple-workspaces" , " blank" , null ),
251
- SSHTest (listOf (" foo-bar" ), " blank" , " append-blank" , " blank" , null ),
252
- SSHTest (listOf (" foo-bar" ), " blank-newlines" , " append-blank-newlines" , " blank" , null ),
253
- SSHTest (listOf (" foo-bar" ), " existing-end" , " replace-end" , " no-blocks" , null ),
254
- SSHTest (listOf (" foo-bar" ), " existing-end-no-newline" , " replace-end-no-newline" , " no-blocks" , null ),
255
- SSHTest (listOf (" foo-bar" ), " existing-middle" , " replace-middle" , " no-blocks" , null ),
256
- SSHTest (listOf (" foo-bar" ), " existing-middle-and-unrelated" , " replace-middle-ignore-unrelated" , " no-related-blocks" , null ),
257
- SSHTest (listOf (" foo-bar" ), " existing-only" , " replace-only" , " blank" , null ),
258
- SSHTest (listOf (" foo-bar" ), " existing-start" , " replace-start" , " no-blocks" , null ),
259
- SSHTest (listOf (" foo-bar" ), " no-blocks" , " append-no-blocks" , " no-blocks" , null ),
260
- SSHTest (listOf (" foo-bar" ), " no-related-blocks" , " append-no-related-blocks" , " no-related-blocks" , null ),
261
- SSHTest (listOf (" foo-bar" ), " no-newline" , " append-no-newline" , " no-blocks" , null ),
250
+ SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" ),
251
+ SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" ),
252
+ SSHTest (listOf (" foo-bar" ), " blank" , " append-blank" , " blank" ),
253
+ SSHTest (listOf (" foo-bar" ), " blank-newlines" , " append-blank-newlines" , " blank" ),
254
+ SSHTest (listOf (" foo-bar" ), " existing-end" , " replace-end" , " no-blocks" ),
255
+ SSHTest (listOf (" foo-bar" ), " existing-end-no-newline" , " replace-end-no-newline" , " no-blocks" ),
256
+ SSHTest (listOf (" foo-bar" ), " existing-middle" , " replace-middle" , " no-blocks" ),
257
+ SSHTest (listOf (" foo-bar" ), " existing-middle-and-unrelated" , " replace-middle-ignore-unrelated" , " no-related-blocks" ),
258
+ SSHTest (listOf (" foo-bar" ), " existing-only" , " replace-only" , " blank" ),
259
+ SSHTest (listOf (" foo-bar" ), " existing-start" , " replace-start" , " no-blocks" ),
260
+ SSHTest (listOf (" foo-bar" ), " no-blocks" , " append-no-blocks" , " no-blocks" ),
261
+ SSHTest (listOf (" foo-bar" ), " no-related-blocks" , " append-no-related-blocks" , " no-related-blocks" ),
262
+ SSHTest (listOf (" foo-bar" ), " no-newline" , " append-no-newline" , " no-blocks" ),
262
263
if (getOS() == OS .WINDOWS ) {
263
264
SSHTest (listOf (" header" ), null , " header-command-windows" , " blank" , """ "C:\Program Files\My Header Command\HeaderCommand.exe" --url="%CODER_URL%" --test="foo bar"""" )
264
265
} else {
265
266
SSHTest (listOf (" header" ), null , " header-command" , " blank" , " my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" )
266
267
},
267
- SSHTest (listOf (" foo" ), null , " disable-autostart" , " blank" , null , true , Features (true )),
268
- SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , null , true , Features (false )),
268
+ SSHTest (listOf (" foo" ), null , " disable-autostart" , " blank" , " " , true , Features (true )),
269
+ SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , " " , true , Features (false )),
270
+ SSHTest (listOf (" extra" ), null , " extra-config" , " blank" ,
271
+ extraConfig = listOf (" ServerAliveInterval 5" ,
272
+ " ServerAliveCountMax 3" ).joinToString(System .lineSeparator())),
269
273
)
270
274
271
275
val newlineRe = " \r ?\n " .toRegex()
@@ -274,7 +278,8 @@ internal class CoderCLIManagerTest {
274
278
val settings = CoderSettings (CoderSettingsState (
275
279
disableAutostart = it.disableAutostart,
276
280
dataDirectory = tmpdir.resolve(" configure-ssh" ).toString(),
277
- headerCommand = it.headerCommand ? : " " ),
281
+ headerCommand = it.headerCommand,
282
+ sshConfigOptions = it.extraConfig),
278
283
sshConfigPath = tmpdir.resolve(it.input + " _to_" + it.output + " .conf" ))
279
284
280
285
val ccm = CoderCLIManager (URL (" https://test.coder.invalid" ), settings)
@@ -295,12 +300,12 @@ internal class CoderCLIManagerTest {
295
300
.replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
296
301
297
302
// Add workspaces.
298
- ccm.configSsh(it.workspaces.toSet(), it.features ? : Features () )
303
+ ccm.configSsh(it.workspaces.toSet(), it.features)
299
304
300
305
assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
301
306
302
307
// Remove configuration.
303
- ccm.configSsh(emptySet(), it.features ? : Features () )
308
+ ccm.configSsh(emptySet(), it.features)
304
309
305
310
// Remove is the configuration we expect after removing.
306
311
assertEquals(
0 commit comments