-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit c3ac5dd.
- Loading branch information
1 parent
9b86bbe
commit 2f42f7c
Showing
9 changed files
with
359 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { OracleDistribution } from '../../src/distributions/oracle/installer'; | ||
import os from 'os'; | ||
import * as core from '@actions/core'; | ||
import { getDownloadArchiveExtension } from '../../src/util'; | ||
|
||
describe('findPackageForDownload', () => { | ||
let distribution: OracleDistribution; | ||
let spyDebug: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
distribution = new OracleDistribution({ | ||
version: '', | ||
architecture: 'x64', | ||
packageType: 'jdk', | ||
checkLatest: false | ||
}); | ||
|
||
spyDebug = jest.spyOn(core, 'debug'); | ||
spyDebug.mockImplementation(() => {}); | ||
}); | ||
|
||
it.each([ | ||
[ | ||
'19', | ||
'19', | ||
'https://download.oracle.com/java/19/latest/jdk-19_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||
], | ||
[ | ||
'19.0.1', | ||
'19.0.1', | ||
'https://download.oracle.com/java/19/archive/jdk-19.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||
], | ||
[ | ||
'18.0.2.1', | ||
'18.0.2.1', | ||
'https://download.oracle.com/java/18/archive/jdk-18.0.2.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||
], | ||
[ | ||
'17', | ||
'17', | ||
'https://download.oracle.com/java/17/latest/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||
], | ||
[ | ||
'17.0.1', | ||
'17.0.1', | ||
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}' | ||
] | ||
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => { | ||
const result = await distribution['findPackageForDownload'](input); | ||
expect(result.version).toBe(expectedVersion); | ||
const osType = distribution.getPlatform(); | ||
const archiveType = getDownloadArchiveExtension(); | ||
const url = expectedUrl.replace('{{OS_TYPE}}', osType).replace('{{ARCHIVE_TYPE}}', archiveType); | ||
expect(result.url).toBe(url); | ||
}); | ||
|
||
it.each([ | ||
['amd64', 'x64'], | ||
['arm64', 'aarch64'] | ||
])( | ||
'defaults to os.arch(): %s mapped to distro arch: %s', | ||
async (osArch: string, distroArch: string) => { | ||
jest.spyOn(os, 'arch').mockReturnValue(osArch); | ||
jest.spyOn(os, 'platform').mockReturnValue('linux'); | ||
|
||
const version = '17'; | ||
const distro = new OracleDistribution({ | ||
version, | ||
architecture: '', // to get default value | ||
packageType: 'jdk', | ||
checkLatest: false | ||
}); | ||
|
||
const osType = distribution.getPlatform(); | ||
if (osType === 'windows' && distroArch == 'aarch64') { | ||
return; // skip, aarch64 is not available for Windows | ||
} | ||
const archiveType = getDownloadArchiveExtension(); | ||
const result = await distro['findPackageForDownload'](version); | ||
const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_${osType}-${distroArch}_bin.${archiveType}`; | ||
|
||
expect(result.url).toBe(expectedUrl); | ||
} | ||
); | ||
|
||
it('should throw an error', async () => { | ||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow( | ||
/Oracle JDK is only supported for JDK 17 and later/ | ||
); | ||
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow( | ||
/Oracle JDK is only supported for JDK 17 and later/ | ||
); | ||
await expect(distribution['findPackageForDownload']('18')).rejects.toThrow( | ||
/Could not find Oracle JDK for SemVer */ | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.