Skip to content

Commit

Permalink
Make tests work on macOS and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 15, 2022
1 parent 46d7903 commit 2910f33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
28 changes: 10 additions & 18 deletions __tests__/distributors/oracle-installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;
Expand Down Expand Up @@ -47,23 +48,9 @@ describe('findPackageForDownload', () => {
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
const result = await distribution['findPackageForDownload'](input);
expect(result.version).toBe(expectedVersion);
let os: string;
let archive: string;
switch (process.platform) {
case 'darwin':
os = 'macos';
archive = 'tar.gz';
break;
case 'win32':
os = 'windows';
archive = 'zip';
break;
default:
os = process.platform.toString();
archive = 'tar.gz';
break;
}
const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive);
const osType = distribution.getPlatform();
const archiveType = getDownloadArchiveExtension();
const url = expectedUrl.replace('{{OS_TYPE}}', osType).replace('{{ARCHIVE_TYPE}}', archiveType);
expect(result.url).toBe(url);
});

Expand All @@ -84,8 +71,13 @@ describe('findPackageForDownload', () => {
checkLatest: false
});

const osType = distribution.getPlatform();
if (osType === 'windows' && distroArch == 'aarch64') {
return; // skip, aarch64 on Windows is not available
}
const archiveType = getDownloadArchiveExtension();
const result = await distro['findPackageForDownload'](version);
const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_linux-${distroArch}_bin.tar.gz`;
const expectedUrl = `https://download.oracle.com/java/17/latest/jdk-17_${osType}-${distroArch}_bin.${archiveType}`;

expect(result.url).toBe(expectedUrl);
}
Expand Down
1 change: 0 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104682,7 +104682,6 @@ class OracleDistribution extends base_installer_1.JavaBase {
case 'darwin':
return 'macos';
case 'win32':
case 'cygwin':
return 'windows';
case 'linux':
return 'linux';
Expand Down
3 changes: 1 addition & 2 deletions src/distributions/oracle/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ export class OracleDistribution extends JavaBase {
return { url: fileUrl, version: range };
}

private getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
switch (platform) {
case 'darwin':
return 'macos';
case 'win32':
case 'cygwin':
return 'windows';
case 'linux':
return 'linux';
Expand Down

0 comments on commit 2910f33

Please sign in to comment.