@@ -33,18 +33,18 @@ import kotlin.test.assertTrue
33
33
34
34
internal class CoderCLIManagerTest {
35
35
private fun mkbin (version : String ):String {
36
- return listOf (" #!/bin/sh" ,""" echo '{"version": "${ version} "}'""" )
36
+ return listOf (" #!/bin/sh" ,""" echo '{"version": "$version "}'""" )
37
37
.joinToString(" \n " )
38
38
}
39
39
40
- private fun mockServer (errorCode : Int = 0):Pair <HttpServer ,URL > {
40
+ private fun mockServer (errorCode : Int = 0, version : String? = null ):Pair <HttpServer ,URL > {
41
41
val srv= HttpServer .create(InetSocketAddress (0 ),0 )
42
42
srv.createContext(" /" ) {exchange->
43
43
var code= HttpURLConnection .HTTP_OK
44
44
// TODO: Is there some simple way to create an executable file on
45
45
// Windows without having to execute something to generate said
46
46
// executable or having to commit one to the repo?
47
- var response= mkbin(" ${srv.address.port} .0.0" )
47
+ var response= mkbin(version ? : " ${srv.address.port} .0.0" )
48
48
val eTags= exchange.requestHeaders[" If-None-Match" ]
49
49
if (exchange.requestURI.path== " /bin/override" ) {
50
50
code= HttpURLConnection .HTTP_OK
@@ -241,7 +241,7 @@ internal class CoderCLIManagerTest {
241
241
val remove : String ,
242
242
val headerCommand : String? ,
243
243
val disableAutostart : Boolean =false ,
244
- val version : SemVer ? =null ,
244
+ val features : Features ? =null ,
245
245
)
246
246
247
247
@Test
@@ -265,11 +265,8 @@ internal class CoderCLIManagerTest {
265
265
}else {
266
266
SSHTest (listOf (" header" ),null ," header-command" ," blank" ," my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" )
267
267
},
268
- SSHTest (listOf (" foo" ),null ," disable-autostart" ," blank" ,null ,true ,SemVer (2 ,5 ,0 )),
269
- SSHTest (listOf (" foo" ),null ," disable-autostart" ," blank" ,null ,true ,SemVer (3 ,5 ,0 )),
270
- SSHTest (listOf (" foo" ),null ," no-disable-autostart" ," blank" ,null ,true ,SemVer (2 ,4 ,9 )),
271
- SSHTest (listOf (" foo" ),null ," no-disable-autostart" ," blank" ,null ,true ,SemVer (1 ,0 ,1 )),
272
- SSHTest (listOf (" foo" ),null ," no-disable-autostart" ," blank" ,null ,true ),
268
+ SSHTest (listOf (" foo" ),null ," disable-autostart" ," blank" ,null ,true ,Features (true )),
269
+ SSHTest (listOf (" foo" ),null ," no-disable-autostart" ," blank" ,null ,true ,Features (false )),
273
270
)
274
271
275
272
val newlineRe= " \r ?\n " .toRegex()
@@ -299,12 +296,12 @@ internal class CoderCLIManagerTest {
299
296
.replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
300
297
301
298
// Add workspaces.
302
- ccm.configSsh(it.workspaces, it.version )
299
+ ccm.configSsh(it.workspaces, it.features )
303
300
304
301
assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
305
302
306
303
// Remove configuration.
307
- ccm.configSsh(emptyList(), it.version )
304
+ ccm.configSsh(emptyList(), it.features )
308
305
309
306
// Remove is the configuration we expect after removing.
310
307
assertEquals(
@@ -554,6 +551,31 @@ internal class CoderCLIManagerTest {
554
551
srv.stop(0 )
555
552
}
556
553
554
+ @Test
555
+ fun testFeatures () {
556
+ if (getOS()== OS .WINDOWS ) {
557
+ return // Cannot execute mock binaries on Windows.
558
+ }
559
+
560
+ val tests= listOf (
561
+ Pair (" 2.5.0" ,Features (true )),
562
+ Pair (" 4.9.0" ,Features (true )),
563
+ Pair (" 2.4.9" ,Features (false )),
564
+ Pair (" 1.0.1" ,Features (false )),
565
+ )
566
+
567
+ tests.forEach {
568
+ val (srv, url)= mockServer(version= it.first)
569
+ val ccm= CoderCLIManager (url,CoderSettings (CoderSettingsState (
570
+ dataDirectory= tmpdir.resolve(" features" ).toString()))
571
+ )
572
+ assertEquals(true , ccm.download())
573
+ assertEquals(it.second, ccm.features," version:${it.first} " )
574
+
575
+ srv.stop(0 )
576
+ }
577
+ }
578
+
557
579
companion object {
558
580
private val tmpdir: Path = Path .of(System .getProperty(" java.io.tmpdir" )).resolve(" coder-gateway-test/cli-manager" )
559
581