|
4 | 4 | package software.aws.toolkits.jetbrains.services.amazonq.lsp
|
5 | 5 |
|
6 | 6 | import com.intellij.execution.configurations.GeneralCommandLine
|
| 7 | +import com.intellij.testFramework.rules.TempDirectory |
| 8 | +import com.intellij.testFramework.utils.io.createFile |
| 9 | +import com.intellij.util.system.CpuArch |
7 | 10 | import org.assertj.core.api.Assertions.assertThat
|
| 11 | +import org.junit.Assume.assumeTrue |
8 | 12 | import org.junit.Rule
|
9 | 13 | import org.junit.Test
|
10 | 14 | import software.aws.toolkits.core.rules.EnvironmentVariableHelper
|
11 |
| -import kotlin.io.path.Path |
| 15 | +import software.aws.toolkits.core.utils.exists |
| 16 | +import java.nio.file.Paths |
12 | 17 |
|
13 | 18 | class NodeExePatcherTest {
|
14 | 19 | @get:Rule
|
15 | 20 | val envVarHelper = EnvironmentVariableHelper()
|
16 | 21 |
|
17 |
| - private val pathToNode = Path("/path/to/node").toAbsolutePath().toString() |
| 22 | + @get:Rule |
| 23 | + val tempDir = TempDirectory() |
| 24 | + |
| 25 | + private val pathToNode = Paths.get("/path/to/node").toAbsolutePath().toString() |
18 | 26 |
|
19 | 27 | @Test
|
20 |
| - fun `patches if path available`() { |
21 |
| - envVarHelper[NodeExePatcher.GLIBC_LINKER_VAR] = "/opt/vsc-sysroot/lib/ld-linux-x86-64.so.2" |
22 |
| - envVarHelper[NodeExePatcher.GLIBC_PATH_VAR] = "/opt/vsc-sysroot/lib/" |
| 28 | + fun `patches if environment variables are available`() { |
| 29 | + val path = tempDir.newDirectory("vsc-sysroot").toPath().toAbsolutePath() |
| 30 | + val linker = Paths.get(path.toString(), "someSharedLibrary").createFile() |
| 31 | + |
| 32 | + envVarHelper[NodeExePatcher.GLIBC_LINKER_VAR] = linker.toString() |
| 33 | + envVarHelper[NodeExePatcher.GLIBC_PATH_VAR] = path.toString() |
| 34 | + |
| 35 | + assertThat(NodeExePatcher.patch(Paths.get("/path/to/node"))) |
| 36 | + .usingComparator(Comparator.comparing { it.commandLineString }) |
| 37 | + .isEqualTo(GeneralCommandLine(linker.toString(), "--library-path", path.toString(), pathToNode)) |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun `patches if hardcoded paths exists`() { |
| 42 | + val path = Paths.get(NodeExePatcher.INTERNAL_GLIBC_PATH) |
| 43 | + // too many permission issues otherwise |
| 44 | + assumeTrue(path.exists()) |
| 45 | + |
| 46 | + val linker = Paths.get(if (CpuArch.isArm64()) NodeExePatcher.INTERNAL_AARCH64_LINKER else NodeExePatcher.INTERNAL_X86_64_LINKER) |
23 | 47 |
|
24 |
| - assertThat(NodeExePatcher.patch(Path("/path/to/node"))) |
| 48 | + assertThat(NodeExePatcher.patch(Paths.get("/path/to/node"))) |
25 | 49 | .usingComparator(Comparator.comparing { it.commandLineString })
|
26 |
| - .isEqualTo(GeneralCommandLine("/opt/vsc-sysroot/lib/ld-linux-x86-64.so.2", "--library-path", "/opt/vsc-sysroot/lib/", pathToNode)) |
| 50 | + .isEqualTo(GeneralCommandLine(linker.toString(), "--library-path", path.toString(), pathToNode)) |
27 | 51 | }
|
28 | 52 |
|
29 | 53 | @Test
|
30 | 54 | fun `noop if no patch available`() {
|
31 |
| - assertThat(NodeExePatcher.patch(Path("/path/to/node"))) |
| 55 | + assertThat(NodeExePatcher.patch(Paths.get("/path/to/node"))) |
32 | 56 | .usingComparator(Comparator.comparing { it.commandLineString })
|
33 | 57 | .isEqualTo(GeneralCommandLine(pathToNode))
|
34 | 58 | }
|
|
0 commit comments