/
PlatformTest.java
96 lines (73 loc) · 3.22 KB
/
PlatformTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.github.eirslett.maven.plugins.frontend.lib;
import java.io.File;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertEquals;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.verifyNoMoreInteractions;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.powermock.api.mockito.PowerMockito.whenNew;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Platform.class, OS.class, Architecture.class, File.class})
public class PlatformTest {
@Test
public void detect_win_doesntLookForAlpine() {
mockStatic(OS.class);
mockStatic(Architecture.class);
when(OS.guess()).thenReturn(OS.Windows);
when(Architecture.guess()).thenReturn(Architecture.x86);
Platform platform = Platform.guess();
assertEquals("win-x86", platform.getNodeClassifier());
verifyNoMoreInteractions(File.class); // doesn't look for a file path
}
@Test
public void detect_arm_mac_download_x64_binary() {
mockStatic(OS.class);
mockStatic(Architecture.class);
when(OS.guess()).thenReturn(OS.Mac);
when(Architecture.guess()).thenReturn(Architecture.arm64);
Platform platform = Platform.guess();
assertEquals("darwin-x64", platform.getNodeClassifier());
}
@Test
public void detect_linux_notAlpine() throws Exception {
mockStatic(OS.class);
mockStatic(Architecture.class);
when(OS.guess()).thenReturn(OS.Linux);
when(Architecture.guess()).thenReturn(Architecture.x86);
File alpineRelease = mock(File.class);
whenNew(File.class)
.withArguments("/etc/alpine-release").thenReturn(alpineRelease);
when(alpineRelease.exists()).thenReturn(false);
Platform platform = Platform.guess();
assertEquals("linux-x86", platform.getNodeClassifier());
assertEquals("https://nodejs.org/dist/", platform.getNodeDownloadRoot());
}
@Test
public void detect_linux_alpine() throws Exception {
mockStatic(OS.class);
mockStatic(Architecture.class);
when(OS.guess()).thenReturn(OS.Linux);
when(Architecture.guess()).thenReturn(Architecture.x86);
File alpineRelease = mock(File.class);
whenNew(File.class).withArguments("/etc/alpine-release")
.thenReturn(alpineRelease);
when(alpineRelease.exists()).thenReturn(true);
Platform platform = Platform.guess();
assertEquals("linux-x86-musl", platform.getNodeClassifier());
assertEquals("https://unofficial-builds.nodejs.org/download/release/",
platform.getNodeDownloadRoot());
}
@Test
public void detect_aix_ppc64() {
mockStatic(OS.class);
mockStatic(Architecture.class);
when(OS.guess()).thenReturn(OS.AIX);
when(Architecture.guess()).thenReturn(Architecture.ppc64);
Platform platform = Platform.guess();
assertEquals("aix-ppc64", platform.getNodeClassifier());
}
}