Skip to content

Commit

Permalink
Initial version of sapmachine-installer.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
skateball authored Jan 19, 2024
1 parent ae257cf commit 8aaefcf
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions __tests__/distributors/sapmachine-installer.test.ts
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);
};
});

0 comments on commit 8aaefcf

Please sign in to comment.