2022-12-16 18:43:51 +01:00
|
|
|
import * as path from 'path'
|
|
|
|
import * as graalvm from '../src/graalvm'
|
|
|
|
import {expect, test} from '@jest/globals'
|
2023-06-13 19:17:04 +02:00
|
|
|
import {getTaggedRelease} from '../src/utils'
|
2023-01-24 10:35:51 +01:00
|
|
|
import {findGraalVMVersion, findHighestJavaVersion} from '../src/graalvm'
|
|
|
|
import {GRAALVM_RELEASES_REPO} from '../src/constants'
|
2022-12-16 18:43:51 +01:00
|
|
|
|
|
|
|
process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
|
|
|
|
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')
|
|
|
|
|
|
|
|
test('request invalid version/javaVersion', async () => {
|
|
|
|
for (var combination of [
|
|
|
|
['22.3.0', '7'],
|
|
|
|
['22.3', '17'],
|
|
|
|
['22.3', '7']
|
|
|
|
]) {
|
|
|
|
let error = new Error('unexpected')
|
|
|
|
try {
|
|
|
|
await graalvm.setUpGraalVMRelease('', combination[0], combination[1])
|
|
|
|
} catch (err) {
|
2023-04-11 09:02:29 +02:00
|
|
|
if (!(err instanceof Error)) {
|
2023-06-16 09:19:49 +02:00
|
|
|
fail(`Unexpected non-Error: ${err}`)
|
2023-04-11 09:02:29 +02:00
|
|
|
}
|
2022-12-16 18:43:51 +01:00
|
|
|
error = err
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).not.toBeUndefined()
|
|
|
|
expect(error.message).toContain('Failed to download')
|
|
|
|
expect(error.message).toContain('Are you sure version')
|
|
|
|
}
|
|
|
|
})
|
2023-01-24 10:35:51 +01:00
|
|
|
|
|
|
|
test('find version/javaVersion', async () => {
|
2023-06-16 09:19:49 +02:00
|
|
|
// Make sure the action can find the latest Java version for known major versions
|
|
|
|
for (var majorJavaVersion of ['17', '20']) {
|
|
|
|
await graalvm.findLatestGraalVMJDKCEJavaVersion(majorJavaVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
let error = new Error('unexpected')
|
|
|
|
try {
|
|
|
|
await graalvm.findLatestGraalVMJDKCEJavaVersion('11')
|
|
|
|
fail('Should not find Java version for 11')
|
|
|
|
} catch (err) {
|
|
|
|
if (!(err instanceof Error)) {
|
|
|
|
fail(`Unexpected non-Error: ${err}`)
|
|
|
|
}
|
|
|
|
error = err
|
|
|
|
}
|
|
|
|
expect(error.message).toContain('Unable to find the latest Java version for')
|
|
|
|
|
2023-06-13 19:17:04 +02:00
|
|
|
const latestRelease = await getTaggedRelease(
|
|
|
|
GRAALVM_RELEASES_REPO,
|
|
|
|
'vm-22.3.1'
|
|
|
|
)
|
2023-01-24 10:35:51 +01:00
|
|
|
const latestVersion = findGraalVMVersion(latestRelease)
|
|
|
|
expect(latestVersion).not.toBe('')
|
|
|
|
const latestJavaVersion = findHighestJavaVersion(latestRelease, latestVersion)
|
|
|
|
expect(latestJavaVersion).not.toBe('')
|
|
|
|
|
2023-06-16 09:19:49 +02:00
|
|
|
error = new Error('unexpected')
|
2023-01-24 10:35:51 +01:00
|
|
|
try {
|
|
|
|
const invalidRelease = {...latestRelease, tag_name: 'invalid'}
|
|
|
|
findGraalVMVersion(invalidRelease)
|
|
|
|
} catch (err) {
|
2023-04-11 09:02:29 +02:00
|
|
|
if (!(err instanceof Error)) {
|
2023-06-13 19:17:04 +02:00
|
|
|
fail(`Unexpected non-Error: ${err}`)
|
2023-04-11 09:02:29 +02:00
|
|
|
}
|
2023-01-24 10:35:51 +01:00
|
|
|
error = err
|
|
|
|
}
|
|
|
|
expect(error.message).toContain('Could not find latest GraalVM release:')
|
|
|
|
|
|
|
|
try {
|
|
|
|
findHighestJavaVersion(latestRelease, 'invalid')
|
|
|
|
} catch (err) {
|
2023-04-11 09:02:29 +02:00
|
|
|
if (!(err instanceof Error)) {
|
2023-06-16 09:19:49 +02:00
|
|
|
fail(`Unexpected non-Error: ${err}`)
|
2023-04-11 09:02:29 +02:00
|
|
|
}
|
2023-01-24 10:35:51 +01:00
|
|
|
error = err
|
|
|
|
}
|
|
|
|
expect(error.message).toContain('Could not find highest Java version.')
|
|
|
|
})
|