2022-02-21 23:49:37 +03:00
|
|
|
import * as _core from '@actions/core'
|
|
|
|
import * as _exec from '@actions/exec'
|
|
|
|
import * as _io from '@actions/io'
|
|
|
|
import * as _tc from '@actions/tool-cache'
|
2022-10-25 13:10:46 +02:00
|
|
|
import * as _http from '@actions/http-client'
|
2022-02-21 23:49:37 +03:00
|
|
|
import * as _os from 'os'
|
2022-03-20 14:17:06 +03:00
|
|
|
import * as _fs from '../src/fs'
|
2022-02-21 23:49:37 +03:00
|
|
|
import {join} from 'path'
|
2022-07-19 12:37:55 +02:00
|
|
|
import {VERSION} from '../src/version'
|
2019-10-04 11:41:15 +02:00
|
|
|
|
2020-09-24 12:19:07 +02:00
|
|
|
import * as tdeps from '../src/cli'
|
2022-02-21 23:49:37 +03:00
|
|
|
|
|
|
|
const toolPath = join(__dirname, 'runner', 'tools', 'tdeps')
|
|
|
|
const tempPath = join(__dirname, 'runner', 'temp', 'tdeps')
|
|
|
|
const downloadPath = join(__dirname, 'runner', 'download')
|
|
|
|
const cachePath = join(__dirname, 'runner', 'cache')
|
|
|
|
|
|
|
|
jest.mock('@actions/core')
|
|
|
|
const core: jest.Mocked<typeof _core> = _core as never
|
|
|
|
|
|
|
|
jest.mock('@actions/exec')
|
|
|
|
const exec: jest.Mocked<typeof _exec> = _exec as never
|
|
|
|
|
|
|
|
jest.mock('@actions/io')
|
|
|
|
const io: jest.Mocked<typeof _io> = _io as never
|
|
|
|
|
|
|
|
jest.mock('@actions/tool-cache')
|
|
|
|
const tc: jest.Mocked<typeof _tc> = _tc as never
|
|
|
|
|
2022-03-20 14:17:06 +03:00
|
|
|
jest.mock('../src/fs')
|
|
|
|
const fs: jest.Mocked<typeof _fs> = _fs as never
|
|
|
|
|
2022-02-21 23:49:37 +03:00
|
|
|
jest.mock('os')
|
|
|
|
const os: jest.Mocked<typeof _os> = _os as never
|
2019-10-04 11:41:15 +02:00
|
|
|
|
2022-10-25 13:10:46 +02:00
|
|
|
jest.mock('@actions/http-client', () => {
|
|
|
|
return {
|
|
|
|
HttpClient: jest.fn().mockImplementation(() => {
|
|
|
|
return {
|
2023-09-06 15:29:15 +02:00
|
|
|
getJson: jest.fn().mockImplementation(() => {
|
2022-10-25 13:10:46 +02:00
|
|
|
return {
|
2023-09-06 15:29:15 +02:00
|
|
|
result: {
|
|
|
|
tag_name: '1.2.3'
|
|
|
|
}
|
2022-10-25 13:10:46 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-10-04 11:41:15 +02:00
|
|
|
describe('tdeps tests', () => {
|
2020-08-20 11:39:44 +02:00
|
|
|
beforeAll(async () => {
|
2022-02-21 23:49:37 +03:00
|
|
|
process.env['RUNNER_TOOL_CACHE'] = toolPath
|
|
|
|
process.env['RUNNER_TEMP'] = tempPath
|
|
|
|
os.arch.mockReturnValue('x64')
|
|
|
|
os.platform.mockReturnValue('linux')
|
|
|
|
jest.spyOn(global.Math, 'random').mockReturnValue(1)
|
|
|
|
})
|
2019-10-04 11:41:15 +02:00
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
afterAll(async () => {
|
2022-02-21 23:49:37 +03:00
|
|
|
jest.spyOn(global.Math, 'random').mockRestore()
|
|
|
|
jest.resetAllMocks()
|
|
|
|
delete process.env['RUNNER_TOOL_CACHE']
|
|
|
|
delete process.env['RUNNER_TEMP']
|
|
|
|
})
|
2019-10-07 12:25:25 +02:00
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
it('Throws if invalid version', async () => {
|
2022-02-21 23:49:37 +03:00
|
|
|
const msg = 'Unexpected HTTP response: 403'
|
|
|
|
tc.downloadTool.mockRejectedValueOnce(new Error(msg))
|
|
|
|
await expect(tdeps.setup('1000')).rejects.toThrow(msg)
|
2020-08-20 11:39:44 +02:00
|
|
|
})
|
2019-10-04 11:41:15 +02:00
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
it('Install clojure tools deps with normal version', async () => {
|
2022-02-21 23:49:37 +03:00
|
|
|
tc.downloadTool.mockResolvedValueOnce(downloadPath)
|
|
|
|
tc.cacheDir.mockResolvedValueOnce(cachePath)
|
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
await tdeps.setup('1.10.1.469')
|
2022-02-21 23:49:37 +03:00
|
|
|
|
|
|
|
expect(tc.downloadTool).toHaveBeenCalledWith(
|
2023-09-06 15:29:15 +02:00
|
|
|
'https://download.clojure.org/install/linux-install-1.10.1.469.sh',
|
|
|
|
undefined,
|
|
|
|
undefined
|
2022-02-21 23:49:37 +03:00
|
|
|
)
|
2022-07-22 10:56:02 +02:00
|
|
|
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
|
2022-02-21 23:49:37 +03:00
|
|
|
expect(exec.exec).toHaveBeenCalledWith('bash', [
|
|
|
|
downloadPath,
|
|
|
|
'--prefix',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
2022-02-21 23:49:37 +03:00
|
|
|
])
|
|
|
|
expect(tc.cacheDir).toHaveBeenCalledWith(
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools',
|
2020-08-20 11:39:44 +02:00
|
|
|
'ClojureToolsDeps',
|
2022-07-19 12:37:55 +02:00
|
|
|
`1.10.1-469-${VERSION}`
|
2020-08-20 11:39:44 +02:00
|
|
|
)
|
2022-02-21 23:49:37 +03:00
|
|
|
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
|
|
'CLOJURE_INSTALL_DIR',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
|
|
|
)
|
|
|
|
expect(core.addPath).toHaveBeenCalledWith(
|
|
|
|
'/tmp/usr/local/opt/ClojureTools/bin'
|
2022-02-21 23:49:37 +03:00
|
|
|
)
|
|
|
|
})
|
2019-10-08 12:46:58 +02:00
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
it('Install latest clojure tools deps', async () => {
|
2022-02-21 23:49:37 +03:00
|
|
|
tc.downloadTool.mockResolvedValueOnce(downloadPath)
|
|
|
|
tc.cacheDir.mockResolvedValueOnce(cachePath)
|
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
await tdeps.setup('latest')
|
2022-02-21 23:49:37 +03:00
|
|
|
|
|
|
|
expect(tc.downloadTool).toHaveBeenCalledWith(
|
2023-09-06 15:29:15 +02:00
|
|
|
'https://download.clojure.org/install/linux-install-1.2.3.sh',
|
|
|
|
undefined,
|
|
|
|
undefined
|
2022-02-21 23:49:37 +03:00
|
|
|
)
|
2022-07-22 10:56:02 +02:00
|
|
|
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
|
2022-02-21 23:49:37 +03:00
|
|
|
expect(exec.exec).toHaveBeenCalledWith('bash', [
|
|
|
|
downloadPath,
|
|
|
|
'--prefix',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
2022-02-21 23:49:37 +03:00
|
|
|
])
|
|
|
|
expect(tc.cacheDir).toHaveBeenCalledWith(
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools',
|
2020-08-20 11:39:44 +02:00
|
|
|
'ClojureToolsDeps',
|
2022-10-25 13:10:46 +02:00
|
|
|
`1.2.3-${VERSION}`
|
2020-08-20 11:39:44 +02:00
|
|
|
)
|
2022-02-21 23:49:37 +03:00
|
|
|
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
|
|
'CLOJURE_INSTALL_DIR',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
|
|
|
)
|
|
|
|
expect(core.addPath).toHaveBeenCalledWith(
|
|
|
|
'/tmp/usr/local/opt/ClojureTools/bin'
|
2022-02-21 23:49:37 +03:00
|
|
|
)
|
|
|
|
})
|
2019-10-04 11:41:15 +02:00
|
|
|
|
2022-03-20 14:17:06 +03:00
|
|
|
it('Supports macOS', async () => {
|
|
|
|
os.platform.mockReturnValue('darwin')
|
|
|
|
|
|
|
|
fs.readFile.mockResolvedValueOnce('install -D')
|
|
|
|
fs.writeFile.mockResolvedValueOnce()
|
|
|
|
|
|
|
|
tc.downloadTool.mockResolvedValueOnce(downloadPath)
|
|
|
|
tc.cacheDir.mockResolvedValueOnce(cachePath)
|
|
|
|
|
2023-09-06 15:29:15 +02:00
|
|
|
await tdeps.setup('latest', 'foo')
|
2022-03-20 14:17:06 +03:00
|
|
|
|
|
|
|
expect(tc.downloadTool).toHaveBeenCalledWith(
|
2023-09-06 15:29:15 +02:00
|
|
|
'https://download.clojure.org/install/linux-install-1.2.3.sh',
|
|
|
|
undefined,
|
|
|
|
'foo'
|
2022-03-20 14:17:06 +03:00
|
|
|
)
|
2022-07-22 10:56:02 +02:00
|
|
|
expect(io.mkdirP).toHaveBeenCalledWith('/tmp/usr/local/opt/ClojureTools')
|
2022-03-20 14:17:06 +03:00
|
|
|
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
|
|
join(__dirname, 'runner/download'),
|
|
|
|
'$(brew --prefix coreutils)/bin/ginstall -D',
|
|
|
|
'utf-8'
|
|
|
|
)
|
|
|
|
expect(exec.exec).toHaveBeenCalledWith('bash', [
|
|
|
|
downloadPath,
|
|
|
|
'--prefix',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
2022-03-20 14:17:06 +03:00
|
|
|
])
|
|
|
|
expect(tc.cacheDir).toHaveBeenCalledWith(
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools',
|
2022-03-20 14:17:06 +03:00
|
|
|
'ClojureToolsDeps',
|
2022-10-25 13:10:46 +02:00
|
|
|
`1.2.3-${VERSION}`
|
2022-03-20 14:17:06 +03:00
|
|
|
)
|
|
|
|
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
|
|
'CLOJURE_INSTALL_DIR',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
|
|
|
)
|
|
|
|
expect(core.addPath).toHaveBeenCalledWith(
|
|
|
|
'/tmp/usr/local/opt/ClojureTools/bin'
|
2022-03-20 14:17:06 +03:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
it('Uses version of clojure tools-deps installed in cache', async () => {
|
2022-02-21 23:49:37 +03:00
|
|
|
tc.find.mockReturnValue(cachePath)
|
|
|
|
|
2020-08-20 11:39:44 +02:00
|
|
|
await tdeps.setup('1.10.1.469')
|
2019-10-04 11:41:15 +02:00
|
|
|
|
2022-02-21 23:49:37 +03:00
|
|
|
expect(core.exportVariable).toHaveBeenCalledWith(
|
|
|
|
'CLOJURE_INSTALL_DIR',
|
2022-07-22 10:56:02 +02:00
|
|
|
'/tmp/usr/local/opt/ClojureTools'
|
|
|
|
)
|
|
|
|
expect(core.addPath).toHaveBeenCalledWith(
|
|
|
|
'/tmp/usr/local/opt/ClojureTools/bin'
|
2020-08-20 11:39:44 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|