-
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathVariantComputerTest.groovy
More file actions
256 lines (205 loc) · 11.2 KB
/
VariantComputerTest.groovy
File metadata and controls
256 lines (205 loc) · 11.2 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package com.github.gradle.node.variant
import com.github.gradle.node.NodeExtension
import com.github.gradle.node.util.PlatformHelper
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification
import spock.lang.Unroll
class VariantComputerTest extends Specification {
/* OS dependant line separator */
static final String PS = File.separator
/* Relative base path for nodejs installation */
static final String NODE_BASE_PATH = "${PS}.gradle${PS}node${PS}"
private Properties props
def setup() {
props = new Properties()
PlatformHelper.INSTANCE = new PlatformHelper(props)
}
@Unroll
def "test variant on windows (#version #osArch)"() {
given:
def project = ProjectBuilder.builder().build()
props.setProperty("os.name", "Windows 8")
props.setProperty("os.arch", osArch)
def nodeExtension = new NodeExtension(project)
nodeExtension.download.set(true)
nodeExtension.version.set(version)
nodeExtension.workDir.set(project.layout.projectDirectory.dir(".gradle/node"))
def nodeDir = "node-v${version}-win-${osArch}".toString()
def depName = "org.nodejs:node:${version}:win-${osArch}@zip".toString()
def variantComputer = new VariantComputer()
when:
def computedArchiveDependency = variantComputer.computeNodeArchiveDependency(nodeExtension)
def computedNodeDir = variantComputer.computeNodeDir(nodeExtension)
def computedNodeBinDir = variantComputer.computeNodeBinDir(computedNodeDir)
def computedNodeExec = variantComputer.computeNodeExec(nodeExtension, computedNodeBinDir)
def computedNpmScriptFile = variantComputer.computeNpmScriptFile(computedNodeDir, "npm")
def computedNpxScriptFile = variantComputer.computeNpmScriptFile(computedNodeDir, "npx")
then:
computedArchiveDependency.get() == depName
computedNodeDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeBinDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeExec.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "node.exe")
computedNpmScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "node_modules${PS}npm${PS}bin${PS}npm-cli.js")
computedNpxScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "node_modules${PS}npm${PS}bin${PS}npx-cli.js")
where:
version | osArch
"4.5.0" | "x86"
"6.2.1" | "x86"
"7.0.0" | "x86"
"4.5.0" | "x64"
"6.2.1" | "x64"
"7.0.0" | "x64"
}
@Unroll
def "test variant on non-windows (#osName, #osArch)"() {
given:
props.setProperty("os.name", osName)
props.setProperty("os.arch", osArch)
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.download.set(true)
nodeExtension.version.set('5.12.0')
nodeExtension.workDir.set(project.layout.projectDirectory.dir(".gradle/node"))
def variantComputer = new VariantComputer()
when:
def computedArchiveDependency = variantComputer.computeNodeArchiveDependency(nodeExtension)
def computedNodeDir = variantComputer.computeNodeDir(nodeExtension)
def computedNodeBinDir = variantComputer.computeNodeBinDir(computedNodeDir)
def computedNodeExec = variantComputer.computeNodeExec(nodeExtension, computedNodeBinDir)
def computedNpmScriptFile = variantComputer.computeNpmScriptFile(computedNodeDir, "npm")
def computedNpxScriptFile = variantComputer.computeNpmScriptFile(computedNodeDir, "npx")
then:
computedArchiveDependency.get() == depName
computedNodeDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeBinDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + 'bin')
computedNodeExec.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "bin${PS}node")
computedNpmScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npm-cli.js")
computedNpxScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npx-cli.js")
where:
osName | osArch | nodeDir | depName
'Linux' | 'x86' | 'node-v5.12.0-linux-x86' | 'org.nodejs:node:5.12.0:linux-x86@tar.gz'
'Linux' | 'x86_64' | 'node-v5.12.0-linux-x64' | 'org.nodejs:node:5.12.0:linux-x64@tar.gz'
'Linux' | 'ppc64le' | 'node-v5.12.0-linux-ppc64le' | 'org.nodejs:node:5.12.0:linux-ppc64le@tar.gz'
'Mac OS X' | 'x86' | 'node-v5.12.0-darwin-x86' | 'org.nodejs:node:5.12.0:darwin-x86@tar.gz'
'Mac OS X' | 'x86_64' | 'node-v5.12.0-darwin-x64' | 'org.nodejs:node:5.12.0:darwin-x64@tar.gz'
'SunOS' | 'x86' | 'node-v5.12.0-sunos-x86' | 'org.nodejs:node:5.12.0:sunos-x86@tar.gz'
'SunOS' | 'x86_64' | 'node-v5.12.0-sunos-x64' | 'org.nodejs:node:5.12.0:sunos-x64@tar.gz'
}
@Unroll
def "test variant on ARM (#osName, #osArch, #sysOsArch)"() {
given:
props.setProperty("os.name", osName)
props.setProperty("os.arch", osArch)
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.download.set(true)
nodeExtension.version.set('5.12.0')
nodeExtension.workDir.set(project.layout.projectDirectory.dir(".gradle/node"))
PlatformHelper platformHelperSpy = (PlatformHelper) Spy(PlatformHelper, constructorArgs: [props])
platformHelperSpy.osArch >> { sysOsArch }
def variantComputer = new VariantComputer(platformHelperSpy)
when:
def computedArchiveDependency = variantComputer.computeNodeArchiveDependency(nodeExtension)
def computedNodeDir = variantComputer.computeNodeDir(nodeExtension)
def computedNodeBinDir = variantComputer.computeNodeBinDir(computedNodeDir)
def computedNodeExec = variantComputer.computeNodeExec(nodeExtension, computedNodeBinDir)
def computedNpmScriptFile = variantComputer.computeNpmScriptFile(computedNodeDir, "npm")
def computedNpxScriptFile = variantComputer.computeNpmScriptFile(computedNodeDir, "npx")
then:
computedArchiveDependency.get() == depName
computedNodeDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeBinDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + 'bin')
computedNodeExec.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "bin${PS}node")
computedNpmScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npm-cli.js")
computedNpxScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npx-cli.js")
where:
osName | osArch | sysOsArch | nodeDir | depName
'Linux' | 'arm' | 'armv6l' | 'node-v5.12.0-linux-armv6l' | 'org.nodejs:node:5.12.0:linux-armv6l@tar.gz'
'Linux' | 'arm' | 'armv7l' | 'node-v5.12.0-linux-armv7l' | 'org.nodejs:node:5.12.0:linux-armv7l@tar.gz'
'Linux' | 'arm' | 'arm64' | 'node-v5.12.0-linux-arm64' | 'org.nodejs:node:5.12.0:linux-arm64@tar.gz'
'Linux' | 'ppc64le' | 'ppc64le' | 'node-v5.12.0-linux-ppc64le' | 'org.nodejs:node:5.12.0:linux-ppc64le@tar.gz'
}
@Unroll
def "test npm paths on windows (npm: #npmVersion, download: #download)"() {
given:
props.setProperty("os.name", "Windows 8")
props.setProperty("os.arch", "x86")
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.download.set(download)
nodeExtension.npmVersion.set(npmVersion)
def variantComputer = new VariantComputer()
when:
def computedNodeDir = variantComputer.computeNodeDir(nodeExtension)
def computedNpmDir = variantComputer.computeNpmDir(nodeExtension, computedNodeDir)
def computedNodeBinDir = variantComputer.computeNodeBinDir(computedNodeDir)
def computedNpmBinDir = variantComputer.computeNpmBinDir(computedNpmDir)
def computedNpmExec = variantComputer.computeNpmExec(nodeExtension, computedNpmBinDir)
def computedNpxExec = variantComputer.computeNpxExec(nodeExtension, computedNpmBinDir)
def npmDir = computedNodeDir.get()
def npm = nodeExtension.npmCommand.get() + ".cmd"
def npx = nodeExtension.npxCommand.get() + ".cmd"
if (npmVersion != "") {
npmDir = nodeExtension.npmWorkDir.get().dir("npm-v${npmVersion}")
}
if (download) {
npm = npmDir.dir(npm).asFile.toString()
npx = npmDir.dir(npx).asFile.toString()
}
then:
computedNpmDir.get() == npmDir
computedNpmExec.get() == npm
computedNpxExec.get() == npx
// if no version use node paths
npmVersion != "" || computedNpmDir.get() == computedNodeDir.get()
npmVersion != "" || computedNpmBinDir.get() == computedNodeBinDir.get()
where:
download | npmVersion
true | "4.0.2"
true | ""
false | "4.0.2"
false | ""
}
@Unroll
def "test npm paths on non-windows (npm: #npmVersion, download: #download)"() {
given:
props.setProperty("os.name", "Linux")
props.setProperty("os.arch", "x86")
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.download.set(download)
nodeExtension.npmVersion.set(npmVersion)
def variantComputer = new VariantComputer()
when:
def computedNodeDir = variantComputer.computeNodeDir(nodeExtension)
def computedNpmDir = variantComputer.computeNpmDir(nodeExtension, computedNodeDir)
def computedNodeBinDir = variantComputer.computeNodeBinDir(computedNodeDir)
def computedNpmBinDir = variantComputer.computeNpmBinDir(computedNpmDir)
def computedNpmExec = variantComputer.computeNpmExec(nodeExtension, computedNpmBinDir)
def computedNpxExec = variantComputer.computeNpxExec(nodeExtension, computedNpmBinDir)
def npmDir = computedNodeDir.get()
def npm = nodeExtension.npmCommand.get()
def npx = nodeExtension.npxCommand.get()
if (npmVersion != "") {
npmDir = nodeExtension.npmWorkDir.get().dir("npm-v${npmVersion}".toString())
}
def npmBinDir = npmDir.dir("bin")
if (download) {
npm = npmBinDir.file(npm).toString()
npx = npmBinDir.file(npx).toString()
}
then:
computedNpmDir.get() == npmDir
computedNpmExec.get() == npm
computedNpxExec.get() == npx
// if no version use node paths
npmVersion != "" || computedNpmDir.get() == computedNodeDir.get()
npmVersion != "" || computedNpmBinDir.get() == computedNodeBinDir.get()
where:
download | npmVersion
true | "4.0.2"
true | ""
false | "4.0.2"
false | ""
}
}