generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.test.ts
120 lines (92 loc) · 3.62 KB
/
main.test.ts
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
import io = require('@actions/io')
import fs = require('fs')
import os = require('os')
import path = require('path')
const toolDir = path.join(__dirname, 'runner', 'tools')
const tempDir = path.join(__dirname, 'runner', 'temp')
process.env['RUNNER_TOOL_CACHE'] = toolDir
process.env['RUNNER_TEMP'] = tempDir
process.env['INPUT_FAIL-FAST'] = 'true'
import * as installer from '../src/installer'
const IS_WINDOWS = os.platform() === 'win32'
describe('installer tests', () => {
beforeAll(async () => {
await io.rmRF(toolDir)
await io.rmRF(tempDir)
})
it('Acquires the max satisfying version range', async () => {
await installer.getKustomize('*')
const kustomizeDir = path.join(toolDir, 'kustomize', '*', os.arch())
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
})
it('Acquires kustomize version 3.2.0', async () => {
await installer.getKustomize('3.2.0')
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch())
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
})
it('Acquires kustomize version 3.2.1', async () => {
await installer.getKustomize('3.2.1')
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
})
it('Acquires kustomize version 3.3.0', async () => {
await installer.getKustomize('3.3.0')
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
} else {
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
expect(() =>
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
).not.toThrow()
}
})
it('Throws if no location contains correct kustomize version', async () => {
let thrown = false
try {
await installer.getKustomize('1000')
} catch {
thrown = true
}
expect(thrown).toBe(true)
})
it('Uses version of kustomize installed in cache', async () => {
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch())
await io.mkdirP(kustomizeDir)
fs.writeFileSync(`${kustomizeDir}.complete`, 'hello')
await installer.getKustomize('3.2.0')
return
})
it('Resolves semantic versions of kustomize installed in cache', async () => {
const kustomizeDir = path.join(toolDir, 'kustomize', '3.0.0', os.arch())
await io.mkdirP(kustomizeDir)
fs.writeFileSync(`${kustomizeDir}.complete`, 'hello')
await installer.getKustomize('3.0.0')
await installer.getKustomize('3.0')
})
})