@@ -3,14 +3,36 @@ package com.coder.gateway.settings
33import com.coder.gateway.util.OS
44import com.coder.gateway.util.getOS
55import com.coder.gateway.util.withPath
6+ import org.junit.jupiter.api.Assertions
67import java.net.URL
78import java.nio.file.Path
9+ import kotlin.test.AfterTest
10+ import kotlin.test.BeforeTest
811import kotlin.test.Test
912import kotlin.test.assertContains
1013import kotlin.test.assertEquals
1114import kotlin.test.assertNotEquals
1215
1316internal class CoderSettingsTest {
17+ private var originalOsName: String? = null
18+ private var originalOsArch: String? = null
19+
20+ private lateinit var store: CoderSettings
21+
22+ @BeforeTest
23+ fun setUp () {
24+ originalOsName = System .getProperty(" os.name" )
25+ originalOsArch = System .getProperty(" os.arch" )
26+ store = CoderSettings (CoderSettingsState ())
27+ System .setProperty(" intellij.testFramework.rethrow.logged.errors" , " false" )
28+ }
29+
30+ @AfterTest
31+ fun tearDown () {
32+ System .setProperty(" os.name" , originalOsName)
33+ System .setProperty(" os.arch" , originalOsArch)
34+ }
35+
1436 @Test
1537 fun testExpands () {
1638 val state = CoderSettingsState ()
@@ -35,13 +57,13 @@ internal class CoderSettingsTest {
3557 CoderSettings (
3658 state,
3759 env =
38- Environment (
39- mapOf (
40- " LOCALAPPDATA" to " /tmp/coder-gateway-test/localappdata" ,
41- " HOME" to " /tmp/coder-gateway-test/home" ,
42- " XDG_DATA_HOME" to " /tmp/coder-gateway-test/xdg-data" ,
60+ Environment (
61+ mapOf (
62+ " LOCALAPPDATA" to " /tmp/coder-gateway-test/localappdata" ,
63+ " HOME" to " /tmp/coder-gateway-test/home" ,
64+ " XDG_DATA_HOME" to " /tmp/coder-gateway-test/xdg-data" ,
65+ ),
4366 ),
44- ),
4567 )
4668 var expected =
4769 when (getOS()) {
@@ -59,12 +81,12 @@ internal class CoderSettingsTest {
5981 CoderSettings (
6082 state,
6183 env =
62- Environment (
63- mapOf (
64- " XDG_DATA_HOME" to " " ,
65- " HOME" to " /tmp/coder-gateway-test/home" ,
84+ Environment (
85+ mapOf (
86+ " XDG_DATA_HOME" to " " ,
87+ " HOME" to " /tmp/coder-gateway-test/home" ,
88+ ),
6689 ),
67- ),
6890 )
6991 expected = " /tmp/coder-gateway-test/home/.local/share/coder-gateway/localhost"
7092
@@ -78,13 +100,13 @@ internal class CoderSettingsTest {
78100 CoderSettings (
79101 state,
80102 env =
81- Environment (
82- mapOf (
83- " LOCALAPPDATA" to " /ignore" ,
84- " HOME" to " /ignore" ,
85- " XDG_DATA_HOME" to " /ignore" ,
103+ Environment (
104+ mapOf (
105+ " LOCALAPPDATA" to " /ignore" ,
106+ " HOME" to " /ignore" ,
107+ " XDG_DATA_HOME" to " /ignore" ,
108+ ),
86109 ),
87- ),
88110 )
89111 expected = " /tmp/coder-gateway-test/data-dir/localhost"
90112 assertEquals(Path .of(expected).toAbsolutePath(), settings.dataDir(url))
@@ -131,13 +153,13 @@ internal class CoderSettingsTest {
131153 CoderSettings (
132154 state,
133155 env =
134- Environment (
135- mapOf (
136- " APPDATA" to " /tmp/coder-gateway-test/cli-appdata" ,
137- " HOME" to " /tmp/coder-gateway-test/cli-home" ,
138- " XDG_CONFIG_HOME" to " /tmp/coder-gateway-test/cli-xdg-config" ,
156+ Environment (
157+ mapOf (
158+ " APPDATA" to " /tmp/coder-gateway-test/cli-appdata" ,
159+ " HOME" to " /tmp/coder-gateway-test/cli-home" ,
160+ " XDG_CONFIG_HOME" to " /tmp/coder-gateway-test/cli-xdg-config" ,
161+ ),
139162 ),
140- ),
141163 )
142164 var expected =
143165 when (getOS()) {
@@ -153,12 +175,12 @@ internal class CoderSettingsTest {
153175 CoderSettings (
154176 state,
155177 env =
156- Environment (
157- mapOf (
158- " XDG_CONFIG_HOME" to " " ,
159- " HOME" to " /tmp/coder-gateway-test/cli-home" ,
178+ Environment (
179+ mapOf (
180+ " XDG_CONFIG_HOME" to " " ,
181+ " HOME" to " /tmp/coder-gateway-test/cli-home" ,
182+ ),
160183 ),
161- ),
162184 )
163185 expected = " /tmp/coder-gateway-test/cli-home/.config/coderv2"
164186 assertEquals(Path .of(expected), settings.coderConfigDir)
@@ -169,14 +191,14 @@ internal class CoderSettingsTest {
169191 CoderSettings (
170192 state,
171193 env =
172- Environment (
173- mapOf (
174- " CODER_CONFIG_DIR" to " /tmp/coder-gateway-test/coder-config-dir" ,
175- " APPDATA" to " /ignore" ,
176- " HOME" to " /ignore" ,
177- " XDG_CONFIG_HOME" to " /ignore" ,
194+ Environment (
195+ mapOf (
196+ " CODER_CONFIG_DIR" to " /tmp/coder-gateway-test/coder-config-dir" ,
197+ " APPDATA" to " /ignore" ,
198+ " HOME" to " /ignore" ,
199+ " XDG_CONFIG_HOME" to " /ignore" ,
200+ ),
178201 ),
179- ),
180202 )
181203 expected = " /tmp/coder-gateway-test/coder-config-dir"
182204 assertEquals(Path .of(expected), settings.coderConfigDir)
@@ -402,4 +424,54 @@ internal class CoderSettingsTest {
402424 assertEquals(true , settings.ignoreSetupFailure)
403425 assertEquals(" test ssh log directory" , settings.sshLogDirectory)
404426 }
427+
428+
429+ @Test
430+ fun `Default CLI and signature for Windows AMD64` () =
431+ assertBinaryAndSignature(" Windows 10" , " amd64" , " coder-windows-amd64.exe" , " coder-windows-amd64.exe.asc" )
432+
433+ @Test
434+ fun `Default CLI and signature for Windows ARM64` () =
435+ assertBinaryAndSignature(" Windows 10" , " aarch64" , " coder-windows-arm64.exe" , " coder-windows-arm64.exe.asc" )
436+
437+ @Test
438+ fun `Default CLI and signature for Linux AMD64` () =
439+ assertBinaryAndSignature(" Linux" , " x86_64" , " coder-linux-amd64" , " coder-linux-amd64.asc" )
440+
441+ @Test
442+ fun `Default CLI and signature for Linux ARM64` () =
443+ assertBinaryAndSignature(" Linux" , " aarch64" , " coder-linux-arm64" , " coder-linux-arm64.asc" )
444+
445+ @Test
446+ fun `Default CLI and signature for Linux ARMV7` () =
447+ assertBinaryAndSignature(" Linux" , " armv7l" , " coder-linux-armv7" , " coder-linux-armv7.asc" )
448+
449+ @Test
450+ fun `Default CLI and signature for Mac AMD64` () =
451+ assertBinaryAndSignature(" Mac OS X" , " x86_64" , " coder-darwin-amd64" , " coder-darwin-amd64.asc" )
452+
453+ @Test
454+ fun `Default CLI and signature for Mac ARM64` () =
455+ assertBinaryAndSignature(" Mac OS X" , " aarch64" , " coder-darwin-arm64" , " coder-darwin-arm64.asc" )
456+
457+ @Test
458+ fun `Default CLI and signature for unknown OS and Arch` () =
459+ assertBinaryAndSignature(null , null , " coder-windows-amd64.exe" , " coder-windows-amd64.exe.asc" )
460+
461+ @Test
462+ fun `Default CLI and signature for unknown Arch fallback on Linux` () =
463+ assertBinaryAndSignature(" Linux" , " mips64" , " coder-linux-amd64" , " coder-linux-amd64.asc" )
464+
465+ private fun assertBinaryAndSignature (
466+ osName : String? ,
467+ arch : String? ,
468+ expectedBinary : String ,
469+ expectedSignature : String
470+ ) {
471+ if (osName == null ) System .clearProperty(" os.name" ) else System .setProperty(" os.name" , osName)
472+ if (arch == null ) System .clearProperty(" os.arch" ) else System .setProperty(" os.arch" , arch)
473+
474+ Assertions .assertEquals(expectedBinary, store.defaultCliBinaryNameByOsAndArch)
475+ Assertions .assertEquals(expectedSignature, store.defaultSignatureNameByOsAndArch)
476+ }
405477}
0 commit comments