@@ -33,18 +33,18 @@ import kotlin.test.assertTrue
3333
3434internal class CoderCLIManagerTest {
3535 private fun mkbin (version : String ): String {
36- return listOf (" #!/bin/sh" , """ echo '{"version": "${ version} "}'""" )
36+ return listOf (" #!/bin/sh" , """ echo '{"version": "$version "}'""" )
3737 .joinToString(" \n " )
3838 }
3939
40- private fun mockServer (errorCode : Int = 0): Pair <HttpServer , URL > {
40+ private fun mockServer (errorCode : Int = 0, version : String? = null ): Pair <HttpServer , URL > {
4141 val srv = HttpServer .create(InetSocketAddress (0 ), 0 )
4242 srv.createContext(" /" ) {exchange ->
4343 var code = HttpURLConnection .HTTP_OK
4444 // TODO: Is there some simple way to create an executable file on
4545 // Windows without having to execute something to generate said
4646 // 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" )
4848 val eTags = exchange.requestHeaders[" If-None-Match" ]
4949 if (exchange.requestURI.path == " /bin/override" ) {
5050 code = HttpURLConnection .HTTP_OK
@@ -241,7 +241,7 @@ internal class CoderCLIManagerTest {
241241 val remove : String ,
242242 val headerCommand : String? ,
243243 val disableAutostart : Boolean = false ,
244- val version : SemVer ? = null ,
244+ val features : Features ? = null ,
245245 )
246246
247247 @Test
@@ -265,11 +265,8 @@ internal class CoderCLIManagerTest {
265265 } else {
266266 SSHTest (listOf (" header" ), null , " header-command" , " blank" , " my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" )
267267 },
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 )),
273270 )
274271
275272 val newlineRe = " \r ?\n " .toRegex()
@@ -299,12 +296,12 @@ internal class CoderCLIManagerTest {
299296 .replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
300297
301298 // Add workspaces.
302- ccm.configSsh(it.workspaces, it.version )
299+ ccm.configSsh(it.workspaces, it.features )
303300
304301 assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
305302
306303 // Remove configuration.
307- ccm.configSsh(emptyList(), it.version )
304+ ccm.configSsh(emptyList(), it.features )
308305
309306 // Remove is the configuration we expect after removing.
310307 assertEquals(
@@ -554,6 +551,31 @@ internal class CoderCLIManagerTest {
554551 srv.stop(0 )
555552 }
556553
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+
557579 companion object {
558580 private val tmpdir: Path = Path .of(System .getProperty(" java.io.tmpdir" )).resolve(" coder-gateway-test/cli-manager" )
559581
0 commit comments