Skip to content

Commit 6b97667

Browse files
committed
Fix some Windows path tests
- The Path.of() converts the slashes. - I am not sure why moving toAbsolutePath() after the resolve makes a difference, but for some reason it does (it becomes c:\tmp instead of just \tmp).
1 parent b761ec0 commit 6b97667

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ open class CoderSettings(
4040
*/
4141
fun dataDir(url: URL): Path {
4242
val dir = if (state.dataDirectory.isBlank()) dataDir
43-
else Path.of(expand(state.dataDirectory)).toAbsolutePath()
44-
return withHost(dir, url)
43+
else Path.of(expand(state.dataDirectory))
44+
return withHost(dir, url).toAbsolutePath()
4545
}
4646

4747
/**
@@ -67,8 +67,8 @@ open class CoderSettings(
6767
fun binPath(url: URL, forceDownloadToData: Boolean = false): Path {
6868
val binaryName = getCoderCLIForOS(getOS(), getArch())
6969
val dir = if (forceDownloadToData || state.binaryDirectory.isBlank()) dataDir(url)
70-
else withHost(Path.of(expand(state.binaryDirectory)).toAbsolutePath(), url)
71-
return dir.resolve(binaryName)
70+
else withHost(Path.of(expand(state.binaryDirectory)), url)
71+
return dir.resolve(binaryName).toAbsolutePath()
7272
}
7373

7474
/**

src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ internal class CoderSettingsTest {
1919
val url = URL("http://localhost")
2020
val home = Path.of(System.getProperty("user.home"))
2121

22-
state.binaryDirectory = "~/coder-gateway-test/expand-bin-dir"
22+
state.binaryDirectory = Path.of("~/coder-gateway-test/expand-bin-dir").toString()
2323
var expected = home.resolve("coder-gateway-test/expand-bin-dir/localhost")
2424
assertEquals(expected.toAbsolutePath(), settings.binPath(url).parent)
2525

26-
state.dataDirectory = "~/coder-gateway-test/expand-data-dir"
26+
state.dataDirectory = Path.of("~/coder-gateway-test/expand-data-dir").toString()
2727
expected = home.resolve("coder-gateway-test/expand-data-dir/localhost")
2828
assertEquals(expected.toAbsolutePath(), settings.dataDir(url))
2929
}

0 commit comments

Comments
 (0)