forked from actions/setup-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of sapmachine-installer.test.ts
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,67 @@ | ||
import {HttpClient} from '@actions/http-client'; | ||
import {JavaInstallerOptions} from '../../src/distributions/base-models'; | ||
|
||
import {SapMachineDistribution} from '../../src/distributions/sapmachine/installer'; | ||
import * as util from '../../src/util'; | ||
import os from 'os'; | ||
import {isGeneratorFunction} from 'util/types'; | ||
|
||
import manifestData from '../data/corretto.json'; | ||
import { SapMachineDistribution } from '../../../../a/setup-java/src/distributions/sapmachine/installer'; | ||
|
||
describe('getAvailableVersions', () => { | ||
let spyHttpClient: jest.SpyInstance; | ||
let spyGetDownloadArchiveExtension: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); | ||
spyHttpClient.mockReturnValue({ | ||
statusCode: 200, | ||
headers: {}, | ||
result: manifestData | ||
}); | ||
spyGetDownloadArchiveExtension = jest.spyOn( | ||
util, | ||
'getDownloadArchiveExtension' | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
jest.clearAllMocks(); | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('getAvailableVersions', () => { | ||
it("should return right download link for version", () => { | ||
let version = '17'; | ||
let platform = 'linux'; | ||
let architecture = 'x64'; | ||
let packageType = 'jdk'; | ||
let installerOptions: JavaInstallerOptions = { | ||
version: version, | ||
architecture: architecture, | ||
packageType: packageType, | ||
checkLatest: false | ||
}; | ||
let distribution = new SapMachineDistribution(installerOptions); | ||
|
||
let actual = distribution['findPackageForDownload'](version); | ||
|
||
let expected: JavaDownloadRelease= { | ||
version: '17', | ||
url: 'https://sap.com/book-a-license' | ||
}; | ||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
|
||
const mockPlatform = ( | ||
distribution: SapMachineDistribution, | ||
platform: string | ||
) => { | ||
distribution['getPlatformOption'] = () => platform; | ||
const mockedExtension = platform === 'windows' ? 'zip' : 'tar.gz'; | ||
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension); | ||
}; | ||
}); |