FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
setup-python/__tests__/find-graalpy.test.ts at main · SecureLayer/setup-python · GitHub
SecureLayer
/
setup-python
Public
forked from
actions/setup-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
4
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
setup-python
/
__tests__
/
find-graalpy.test.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
432 lines (378 loc) · 12.7 KB
Breadcrumbs
setup-python
/
__tests__
/
find-graalpy.test.ts
Copy path
File metadata and controls
432 lines (378 loc) · 12.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
import
{
jest
,
describe
,
it
,
expect
,
beforeEach
,
afterEach
}
from
'@jest/globals'
;
import
{
fileURLToPath
}
from
'url'
;
import
fs
from
'fs'
;
import
*
as
path
from
'path'
;
const
__dirname
=
path
.
dirname
(
fileURLToPath
(
import
.
meta
.
url
)
)
;
import
*
as
semver
from
'semver'
;
// Mock
@actions
modules
jest
.
unstable_mockModule
(
'@actions/core'
,
(
)
=>
(
{
info
:
jest
.
fn
(
)
,
warning
:
jest
.
fn
(
)
,
debug
:
jest
.
fn
(
)
,
error
:
jest
.
fn
(
)
,
notice
:
jest
.
fn
(
)
,
setFailed
:
jest
.
fn
(
)
,
setOutput
:
jest
.
fn
(
)
,
getInput
:
jest
.
fn
(
)
,
getBooleanInput
:
jest
.
fn
(
)
,
getMultilineInput
:
jest
.
fn
(
)
,
addPath
:
jest
.
fn
(
)
,
exportVariable
:
jest
.
fn
(
)
,
saveState
:
jest
.
fn
(
)
,
getState
:
jest
.
fn
(
)
,
setSecret
:
jest
.
fn
(
)
,
isDebug
:
jest
.
fn
(
(
)
=>
false
)
,
startGroup
:
jest
.
fn
(
)
,
endGroup
:
jest
.
fn
(
)
,
group
:
jest
.
fn
(
(
_name
:
string
,
fn
:
(
)
=>
Promise
<
unknown
>
)
=>
fn
(
)
)
,
toPlatformPath
:
jest
.
fn
(
(
p
:
string
)
=>
p
)
,
toWin32Path
:
jest
.
fn
(
(
p
:
string
)
=>
p
)
,
toPosixPath
:
jest
.
fn
(
(
p
:
string
)
=>
p
)
}
)
)
;
jest
.
unstable_mockModule
(
'@actions/tool-cache'
,
(
)
=>
(
{
find
:
jest
.
fn
(
)
,
findAllVersions
:
jest
.
fn
(
)
,
downloadTool
:
jest
.
fn
(
)
,
extractZip
:
jest
.
fn
(
)
,
extractTar
:
jest
.
fn
(
)
,
extract7z
:
jest
.
fn
(
)
,
extractXar
:
jest
.
fn
(
)
,
cacheDir
:
jest
.
fn
(
)
,
cacheFile
:
jest
.
fn
(
)
,
getManifestFromRepo
:
jest
.
fn
(
)
,
findFromManifest
:
jest
.
fn
(
)
,
evaluateVersions
:
jest
.
fn
(
)
}
)
)
;
jest
.
unstable_mockModule
(
'@actions/exec'
,
(
)
=>
(
{
exec
:
jest
.
fn
(
)
,
getExecOutput
:
jest
.
fn
(
)
}
)
)
;
// Dynamic imports after mocking
const
core
=
await
import
(
'@actions/core'
)
;
const
tc
=
await
import
(
'@actions/tool-cache'
)
;
const
exec
=
await
import
(
'@actions/exec'
)
;
const
finder
=
await
import
(
'../src/find-graalpy.js'
)
;
const
utils
=
await
import
(
'../src/utils.js'
)
;
// Non-mocked imports
import
{
HttpClient
}
from
'@actions/http-client'
;
import
type
*
as
ifm
from
'@actions/http-client/lib/interfaces'
;
import
type
{
IGraalPyManifestRelease
}
from
'../src/utils.js'
;
import
manifestData
from
'./data/graalpy.json'
with
{
type
:
'json'
}
;
const
architecture
=
'x64'
;
const
toolDir
=
path
.
join
(
__dirname
,
'runner'
,
'tools'
)
;
const
tempDir
=
path
.
join
(
__dirname
,
'runner'
,
'temp'
)
;
describe
(
'parseGraalPyVersion'
,
(
)
=>
{
it
.
each
(
[
[
'graalpy-23'
,
'23'
]
,
[
'graalpy-23.0'
,
'23.0'
]
,
[
'graalpy23.0'
,
'23.0'
]
]
)
(
'%s -> %s'
,
(
input
,
expected
)
=>
{
expect
(
finder
.
parseGraalPyVersion
(
input
)
)
.
toEqual
(
expected
)
;
}
)
;
it
.
each
(
[
''
,
'graalpy-'
,
'graalpy'
,
'p'
,
'notgraalpy-'
]
)
(
'throw on invalid input "%s"'
,
input
=>
{
expect
(
(
)
=>
finder
.
parseGraalPyVersion
(
input
)
)
.
toThrow
(
"Invalid 'version' property for GraalPy. GraalPy version should be specified as 'graalpy<python-version>' or 'graalpy-<python-version>'. See README for examples and documentation."
)
;
}
)
;
}
)
;
describe
(
'findGraalPyToolCache'
,
(
)
=>
{
const
actualGraalPyVersion
=
'23.0.0'
;
const
graalpyPath
=
path
.
join
(
'GraalPy'
,
actualGraalPyVersion
,
architecture
)
;
let
tcFind
:
jest
.
Mock
;
let
infoSpy
:
jest
.
Mock
;
let
warningSpy
:
jest
.
Mock
;
let
debugSpy
:
jest
.
Mock
;
let
addPathSpy
:
jest
.
Mock
;
let
exportVariableSpy
:
jest
.
Mock
;
let
setOutputSpy
:
jest
.
Mock
;
beforeEach
(
(
)
=>
{
tcFind
=
tc
.
find
as
jest
.
Mock
;
(
tcFind
as
jest
.
Mock
<
typeof
tc
.
find
>
)
.
mockImplementation
(
(
toolname
:
string
,
pythonVersion
:
string
)
=>
{
const
semverVersion
=
new
semver
.
Range
(
pythonVersion
)
;
return
semver
.
satisfies
(
actualGraalPyVersion
,
semverVersion
)
?
graalpyPath
:
''
;
}
)
;
infoSpy
=
core
.
info
as
jest
.
Mock
;
infoSpy
.
mockImplementation
(
(
)
=>
null
)
;
warningSpy
=
core
.
warning
as
jest
.
Mock
;
warningSpy
.
mockImplementation
(
(
)
=>
null
)
;
debugSpy
=
core
.
debug
as
jest
.
Mock
;
debugSpy
.
mockImplementation
(
(
)
=>
null
)
;
addPathSpy
=
core
.
addPath
as
jest
.
Mock
;
addPathSpy
.
mockImplementation
(
(
)
=>
null
)
;
exportVariableSpy
=
core
.
exportVariable
as
jest
.
Mock
;
exportVariableSpy
.
mockImplementation
(
(
)
=>
null
)
;
setOutputSpy
=
core
.
setOutput
as
jest
.
Mock
;
setOutputSpy
.
mockImplementation
(
(
)
=>
null
)
;
}
)
;
afterEach
(
(
)
=>
{
jest
.
resetAllMocks
(
)
;
jest
.
clearAllMocks
(
)
;
jest
.
restoreAllMocks
(
)
;
}
)
;
it
(
'GraalPy exists on the path and versions are satisfied'
,
(
)
=>
{
expect
(
finder
.
findGraalPyToolCache
(
'23.0.0'
,
architecture
)
)
.
toEqual
(
{
installDir
:
graalpyPath
,
resolvedGraalPyVersion
:
actualGraalPyVersion
}
)
;
}
)
;
it
(
'GraalPy exists on the path and versions are satisfied with semver'
,
(
)
=>
{
expect
(
finder
.
findGraalPyToolCache
(
'23.0'
,
architecture
)
)
.
toEqual
(
{
installDir
:
graalpyPath
,
resolvedGraalPyVersion
:
actualGraalPyVersion
}
)
;
}
)
;
it
(
"GraalPy exists on the path, but version doesn't match"
,
(
)
=>
{
expect
(
finder
.
findGraalPyToolCache
(
'22.3'
,
architecture
)
)
.
toEqual
(
{
installDir
:
''
,
resolvedGraalPyVersion
:
''
}
)
;
}
)
;
}
)
;
describe
(
'findGraalPyVersion'
,
(
)
=>
{
let
getBooleanInputSpy
:
jest
.
Mock
;
let
warningSpy
:
jest
.
Mock
;
let
debugSpy
:
jest
.
Mock
;
let
infoSpy
:
jest
.
Mock
;
let
addPathSpy
:
jest
.
Mock
;
let
exportVariableSpy
:
jest
.
Mock
;
let
setOutputSpy
:
jest
.
Mock
;
let
tcFind
:
jest
.
Mock
;
let
spyExtractZip
:
jest
.
Mock
;
let
spyExtractTar
:
jest
.
Mock
;
let
spyHttpClient
:
jest
.
SpiedFunction
<
typeof
HttpClient
.
prototype
.
getJson
>
;
let
spyExistsSync
:
jest
.
SpiedFunction
<
typeof
fs
.
existsSync
>
;
let
spyExec
:
jest
.
Mock
;
let
spySymlinkSync
:
jest
.
SpiedFunction
<
typeof
fs
.
symlinkSync
>
;
let
spyDownloadTool
:
jest
.
Mock
;
let
spyFsReadDir
:
jest
.
SpiedFunction
<
typeof
fs
.
readdirSync
>
;
let
spyCacheDir
:
jest
.
Mock
;
let
spyChmodSync
:
jest
.
SpiedFunction
<
typeof
fs
.
chmodSync
>
;
let
spyCoreAddPath
:
jest
.
Mock
;
let
spyCoreExportVariable
:
jest
.
Mock
;
const
env
=
process
.
env
;
beforeEach
(
(
)
=>
{
getBooleanInputSpy
=
core
.
getBooleanInput
as
jest
.
Mock
;
getBooleanInputSpy
.
mockImplementation
(
(
)
=>
false
)
;
infoSpy
=
core
.
info
as
jest
.
Mock
;
infoSpy
.
mockImplementation
(
(
)
=>
{
}
)
;
warningSpy
=
core
.
warning
as
jest
.
Mock
;
warningSpy
.
mockImplementation
(
(
)
=>
null
)
;
debugSpy
=
core
.
debug
as
jest
.
Mock
;
debugSpy
.
mockImplementation
(
(
)
=>
null
)
;
addPathSpy
=
core
.
addPath
as
jest
.
Mock
;
addPathSpy
.
mockImplementation
(
(
)
=>
null
)
;
exportVariableSpy
=
core
.
exportVariable
as
jest
.
Mock
;
exportVariableSpy
.
mockImplementation
(
(
)
=>
null
)
;
setOutputSpy
=
core
.
setOutput
as
jest
.
Mock
;
setOutputSpy
.
mockImplementation
(
(
)
=>
null
)
;
process
.
env
=
{
...
env
}
;
tcFind
=
tc
.
find
as
jest
.
Mock
;
(
tcFind
as
jest
.
Mock
<
typeof
tc
.
find
>
)
.
mockImplementation
(
(
tool
:
string
,
version
:
string
)
=>
{
const
semverRange
=
new
semver
.
Range
(
version
)
;
let
graalpyPath
=
''
;
if
(
semver
.
satisfies
(
'23.0.0'
,
semverRange
)
)
{
graalpyPath
=
path
.
join
(
toolDir
,
'GraalPy'
,
'23.0.0'
,
architecture
)
;
}
return
graalpyPath
;
}
)
;
spyDownloadTool
=
tc
.
downloadTool
as
jest
.
Mock
;
spyDownloadTool
.
mockImplementation
(
(
)
=>
path
.
join
(
tempDir
,
'GraalPy'
)
)
;
spyExtractZip
=
tc
.
extractZip
as
jest
.
Mock
;
spyExtractZip
.
mockImplementation
(
(
)
=>
tempDir
)
;
spyExtractTar
=
tc
.
extractTar
as
jest
.
Mock
;
spyExtractTar
.
mockImplementation
(
(
)
=>
tempDir
)
;
spyFsReadDir
=
jest
.
spyOn
(
fs
,
'readdirSync'
)
;
spyFsReadDir
.
mockImplementation
(
(
)
=>
[
'GraalPyTest'
]
as
any
)
;
spyHttpClient
=
jest
.
spyOn
(
HttpClient
.
prototype
,
'getJson'
)
;
spyHttpClient
.
mockImplementation
(
async
(
)
:
Promise
<
ifm
.
TypedResponse
<
IGraalPyManifestRelease
[
]
>
>
=>
{
const
result
=
JSON
.
stringify
(
manifestData
)
;
return
{
statusCode
:
200
,
headers
:
{
}
,
result
:
JSON
.
parse
(
result
)
as
IGraalPyManifestRelease
[
]
}
;
}
)
;
spyExec
=
exec
.
exec
as
jest
.
Mock
;
spyExec
.
mockImplementation
(
(
)
=>
undefined
)
;
spySymlinkSync
=
jest
.
spyOn
(
fs
,
'symlinkSync'
)
;
spySymlinkSync
.
mockImplementation
(
(
)
=>
undefined
)
;
spyExistsSync
=
jest
.
spyOn
(
fs
,
'existsSync'
)
;
spyExistsSync
.
mockReturnValue
(
true
)
;
spyCoreAddPath
=
core
.
addPath
as
jest
.
Mock
;
spyCoreExportVariable
=
core
.
exportVariable
as
jest
.
Mock
;
}
)
;
afterEach
(
(
)
=>
{
jest
.
resetAllMocks
(
)
;
jest
.
clearAllMocks
(
)
;
jest
.
restoreAllMocks
(
)
;
process
.
env
=
env
;
}
)
;
it
(
'found GraalPy in toolcache'
,
async
(
)
=>
{
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-23.0'
,
architecture
,
true
,
false
,
false
)
)
.
resolves
.
toEqual
(
'23.0.0'
)
;
expect
(
spyCoreAddPath
)
.
toHaveBeenCalled
(
)
;
expect
(
spyCoreExportVariable
)
.
toHaveBeenCalledWith
(
'pythonLocation'
,
expect
.
anything
(
)
)
;
expect
(
spyCoreExportVariable
)
.
toHaveBeenCalledWith
(
'PKG_CONFIG_PATH'
,
expect
.
anything
(
)
)
;
}
)
;
it
(
'throw on invalid input format'
,
async
(
)
=>
{
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-x23'
,
architecture
,
true
,
false
,
false
)
)
.
rejects
.
toThrow
(
)
;
}
)
;
it
(
'found and install successfully'
,
async
(
)
=>
{
spyCacheDir
=
tc
.
cacheDir
as
jest
.
Mock
;
spyCacheDir
.
mockImplementation
(
(
)
=>
path
.
join
(
toolDir
,
'GraalPy'
,
'23.0.0'
,
architecture
)
)
;
spyChmodSync
=
jest
.
spyOn
(
fs
,
'chmodSync'
)
;
spyChmodSync
.
mockImplementation
(
(
)
=>
undefined
)
;
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-23.0.0'
,
architecture
,
true
,
false
,
false
)
)
.
resolves
.
toEqual
(
'23.0.0'
)
;
expect
(
spyCoreAddPath
)
.
toHaveBeenCalled
(
)
;
expect
(
spyCoreExportVariable
)
.
toHaveBeenCalledWith
(
'pythonLocation'
,
expect
.
anything
(
)
)
;
expect
(
spyCoreExportVariable
)
.
toHaveBeenCalledWith
(
'PKG_CONFIG_PATH'
,
expect
.
anything
(
)
)
;
}
)
;
it
(
'found and install successfully without environment update'
,
async
(
)
=>
{
spyCacheDir
=
tc
.
cacheDir
as
jest
.
Mock
;
spyCacheDir
.
mockImplementation
(
(
)
=>
path
.
join
(
toolDir
,
'GraalPy'
,
'23.0.0'
,
architecture
)
)
;
spyChmodSync
=
jest
.
spyOn
(
fs
,
'chmodSync'
)
;
spyChmodSync
.
mockImplementation
(
(
)
=>
undefined
)
;
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-23.0.0'
,
architecture
,
false
,
false
,
false
)
)
.
resolves
.
toEqual
(
'23.0.0'
)
;
expect
(
spyCoreAddPath
)
.
not
.
toHaveBeenCalled
(
)
;
expect
(
spyCoreExportVariable
)
.
not
.
toHaveBeenCalled
(
)
;
}
)
;
it
(
'throw if release is not found'
,
async
(
)
=>
{
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-19.0.0'
,
architecture
,
true
,
false
,
false
)
)
.
rejects
.
toThrow
(
`GraalPy version 19.0.0 with arch
${
architecture
}
not found`
)
;
}
)
;
it
(
'check-latest enabled version found and used from toolcache'
,
async
(
)
=>
{
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-23.0.0'
,
architecture
,
false
,
true
,
false
)
)
.
resolves
.
toEqual
(
'23.0.0'
)
;
expect
(
infoSpy
)
.
toHaveBeenCalledWith
(
'Resolved as GraalPy 23.0.0'
)
;
}
)
;
it
(
'check-latest enabled version found and install successfully'
,
async
(
)
=>
{
spyCacheDir
=
tc
.
cacheDir
as
jest
.
Mock
;
spyCacheDir
.
mockImplementation
(
(
)
=>
path
.
join
(
toolDir
,
'GraalPy'
,
'23.0.0'
,
architecture
)
)
;
spyChmodSync
=
jest
.
spyOn
(
fs
,
'chmodSync'
)
;
spyChmodSync
.
mockImplementation
(
(
)
=>
undefined
)
;
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-23.0.0'
,
architecture
,
false
,
true
,
false
)
)
.
resolves
.
toEqual
(
'23.0.0'
)
;
expect
(
infoSpy
)
.
toHaveBeenCalledWith
(
'Resolved as GraalPy 23.0.0'
)
;
}
)
;
it
(
'check-latest enabled version is not found and used from toolcache'
,
async
(
)
=>
{
(
tcFind
as
jest
.
Mock
<
typeof
tc
.
find
>
)
.
mockImplementationOnce
(
(
tool
:
string
,
version
:
string
)
=>
{
const
semverRange
=
new
semver
.
Range
(
version
)
;
let
graalpyPath
=
''
;
if
(
semver
.
satisfies
(
'22.3.4'
,
semverRange
)
)
{
graalpyPath
=
path
.
join
(
toolDir
,
'GraalPy'
,
'22.3.4'
,
architecture
)
;
}
return
graalpyPath
;
}
)
;
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy-22.3.4'
,
architecture
,
false
,
true
,
false
)
)
.
resolves
.
toEqual
(
'22.3.4'
)
;
expect
(
infoSpy
)
.
toHaveBeenCalledWith
(
'Failed to resolve GraalPy 22.3.4 from manifest'
)
;
}
)
;
it
(
'found and install successfully, pre-release fallback'
,
async
(
)
=>
{
spyCacheDir
=
tc
.
cacheDir
as
jest
.
Mock
;
spyCacheDir
.
mockImplementation
(
(
)
=>
path
.
join
(
toolDir
,
'GraalPy'
,
'24.1'
,
architecture
)
)
;
spyChmodSync
=
jest
.
spyOn
(
fs
,
'chmodSync'
)
;
spyChmodSync
.
mockImplementation
(
(
)
=>
undefined
)
;
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy24.1'
,
architecture
,
false
,
false
,
false
)
)
.
rejects
.
toThrow
(
)
;
await
expect
(
finder
.
findGraalPyVersion
(
'graalpy24.1'
,
architecture
,
false
,
false
,
true
)
)
.
resolves
.
toEqual
(
'24.1.0-ea.9'
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL