2024-03-26 13:56:00 +00:00
|
|
|
import {
|
|
|
|
getManifest,
|
|
|
|
getManifestFromRepo,
|
|
|
|
getManifestFromURL
|
|
|
|
} from '../src/install-python';
|
|
|
|
import * as httpm from '@actions/http-client';
|
|
|
|
import * as tc from '@actions/tool-cache';
|
|
|
|
|
|
|
|
jest.mock('@actions/http-client');
|
|
|
|
jest.mock('@actions/tool-cache');
|
|
|
|
|
2024-09-25 09:02:22 +00:00
|
|
|
const mockManifest = [
|
|
|
|
{
|
|
|
|
version: '3.9.0',
|
|
|
|
stable: true,
|
|
|
|
release_url: 'https://example.com/release-url',
|
|
|
|
files: [
|
|
|
|
{
|
|
|
|
filename: 'python-3.9.0-macosx10.9.pkg',
|
|
|
|
arch: 'x64',
|
|
|
|
platform: 'darwin',
|
|
|
|
download_url: 'https://example.com/download-url'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
2024-03-26 13:56:00 +00:00
|
|
|
|
|
|
|
describe('getManifest', () => {
|
|
|
|
it('should return manifest from repo', async () => {
|
|
|
|
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
|
|
|
|
const manifest = await getManifest();
|
|
|
|
expect(manifest).toEqual(mockManifest);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return manifest from URL if repo fetch fails', async () => {
|
|
|
|
(tc.getManifestFromRepo as jest.Mock).mockRejectedValue(
|
|
|
|
new Error('Fetch failed')
|
|
|
|
);
|
|
|
|
(httpm.HttpClient.prototype.getJson as jest.Mock).mockResolvedValue({
|
|
|
|
result: mockManifest
|
|
|
|
});
|
|
|
|
const manifest = await getManifest();
|
|
|
|
expect(manifest).toEqual(mockManifest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getManifestFromRepo', () => {
|
|
|
|
it('should return manifest from repo', async () => {
|
|
|
|
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
|
|
|
|
const manifest = await getManifestFromRepo();
|
|
|
|
expect(manifest).toEqual(mockManifest);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getManifestFromURL', () => {
|
|
|
|
it('should return manifest from URL', async () => {
|
|
|
|
(httpm.HttpClient.prototype.getJson as jest.Mock).mockResolvedValue({
|
|
|
|
result: mockManifest
|
|
|
|
});
|
|
|
|
const manifest = await getManifestFromURL();
|
|
|
|
expect(manifest).toEqual(mockManifest);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw error if unable to get manifest from URL', async () => {
|
|
|
|
(httpm.HttpClient.prototype.getJson as jest.Mock).mockResolvedValue({
|
|
|
|
result: null
|
|
|
|
});
|
|
|
|
await expect(getManifestFromURL()).rejects.toThrow(
|
|
|
|
'Unable to get manifest from'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|