From c19d52bc931fe570c8b4405bc85f23c6b3796981 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Wed, 7 Jun 2023 16:18:17 +0200 Subject: [PATCH 1/2] Add mock data for microsoft-installer --- __tests__/data/microsoft.json | 218 ++++++++++++++++++ .../distributors/microsoft-installer.test.ts | 2 +- 2 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 __tests__/data/microsoft.json diff --git a/__tests__/data/microsoft.json b/__tests__/data/microsoft.json new file mode 100644 index 0000000..e566901 --- /dev/null +++ b/__tests__/data/microsoft.json @@ -0,0 +1,218 @@ +[ + { + "version": "17.0.7", + "stable": true, + "release_url": "https://aka.ms/download-jdk", + "files": [ + { + "filename": "microsoft-jdk-17.0.7-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.7-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.7-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-17.0.7-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.7-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.7-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "17.0.1+12.1", + "stable": true, + "release_url": "https://aka.ms/download-jdk", + "files": [ + { + "filename": "microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "16.0.2+7.1", + "stable": true, + "release_url": "https://aka.ms/download-jdk", + "files": [ + { + "filename": "microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-16.0.2.7.1-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "11.0.19", + "stable": true, + "release_url": "https://aka.ms/download-jdk", + "files": [ + { + "filename": "microsoft-jdk-11.0.19-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.19-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.19-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-11.0.19-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.19-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.19-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "11.0.15", + "stable": true, + "release_url": "https://aka.ms/download-jdk", + "files": [ + { + "filename": "microsoft-jdk-11.0.15-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.15-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.15-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-11.0.15-macos-aarch64.tar.gz", + "arch": "aarch64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-macos-aarch64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.15-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.15-linux-aarch64.tar.gz" + } + ] + }, + { + "version": "11.0.13+8.1", + "stable": true, + "release_url": "https://aka.ms/download-jdk", + "files": [ + { + "filename": "microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz", + "arch": "x64", + "platform": "darwin", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-macos-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz", + "arch": "x64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-x64.tar.gz" + }, + { + "filename": "microsoft-jdk-11.0.13.8.1-windows-x64.zip", + "arch": "x64", + "platform": "win32", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-windows-x64.zip" + }, + { + "filename": "microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz", + "arch": "aarch64", + "platform": "linux", + "download_url": "https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-linux-aarch64.tar.gz" + } + ] + } +] diff --git a/__tests__/distributors/microsoft-installer.test.ts b/__tests__/distributors/microsoft-installer.test.ts index cf32cef..45688d5 100644 --- a/__tests__/distributors/microsoft-installer.test.ts +++ b/__tests__/distributors/microsoft-installer.test.ts @@ -1,6 +1,6 @@ import {MicrosoftDistributions} from '../../src/distributions/microsoft/installer'; import os from 'os'; -import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json'; +import data from '../data/microsoft.json'; import * as httpm from '@actions/http-client'; import * as core from '@actions/core'; From 07b6c30c67127b33606c6a237272ad077b133352 Mon Sep 17 00:00:00 2001 From: Nikolai Laevskii Date: Wed, 7 Jun 2023 16:18:29 +0200 Subject: [PATCH 2/2] Add mocks for oracle installer --- __tests__/distributors/oracle-installer.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/__tests__/distributors/oracle-installer.test.ts b/__tests__/distributors/oracle-installer.test.ts index 7491b77..2f133fc 100644 --- a/__tests__/distributors/oracle-installer.test.ts +++ b/__tests__/distributors/oracle-installer.test.ts @@ -2,10 +2,12 @@ import {OracleDistribution} from '../../src/distributions/oracle/installer'; import os from 'os'; import * as core from '@actions/core'; import {getDownloadArchiveExtension} from '../../src/util'; +import {HttpClient} from '@actions/http-client'; describe('findPackageForDownload', () => { let distribution: OracleDistribution; let spyDebug: jest.SpyInstance; + let spyHttpClient: jest.SpyInstance; beforeEach(() => { distribution = new OracleDistribution({ @@ -41,7 +43,20 @@ describe('findPackageForDownload', () => { '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) => { + /* Needed only for this particular test because /latest/ urls tend to change */ + spyHttpClient = jest.spyOn(HttpClient.prototype, 'head'); + spyHttpClient.mockReturnValue( + Promise.resolve({ + message: { + statusCode: 200 + } + }) + ); + const result = await distribution['findPackageForDownload'](input); + + jest.restoreAllMocks(); + expect(result.version).toBe(expectedVersion); const osType = distribution.getPlatform(); const archiveType = getDownloadArchiveExtension();