mirror of
https://github.com/actions/setup-python.git
synced 2024-11-15 03:45:01 -05:00
05fb98de9a
* initial changes * updated version * format check * refactored code * updated test cases * Update src/utils.ts Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> * Update utils.ts * Update utils.test.ts * review comments * dist update * Review comment * update version * updated version Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import * as cache from '@actions/cache';
|
|
import * as core from '@actions/core';
|
|
import {
|
|
validateVersion,
|
|
validatePythonVersionFormatForPyPy,
|
|
isCacheFeatureAvailable
|
|
} from '../src/utils';
|
|
|
|
jest.mock('@actions/cache');
|
|
jest.mock('@actions/core');
|
|
|
|
describe('validatePythonVersionFormatForPyPy', () => {
|
|
it.each([
|
|
['3.6', true],
|
|
['3.7', true],
|
|
['3.6.x', false],
|
|
['3.7.x', false],
|
|
['3.x', false],
|
|
['3', false]
|
|
])('%s -> %s', (input, expected) => {
|
|
expect(validatePythonVersionFormatForPyPy(input)).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe('validateVersion', () => {
|
|
it.each([
|
|
['v7.3.3', true],
|
|
['v7.3.x', true],
|
|
['v7.x', true],
|
|
['x', true],
|
|
['v7.3.3-rc.1', true],
|
|
['nightly', true],
|
|
['v7.3.b', false],
|
|
['3.6', true],
|
|
['3.b', false],
|
|
['3', true]
|
|
])('%s -> %s', (input, expected) => {
|
|
expect(validateVersion(input)).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe('isCacheFeatureAvailable', () => {
|
|
it('isCacheFeatureAvailable disabled on GHES', () => {
|
|
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
|
|
try {
|
|
process.env['GITHUB_SERVER_URL'] = 'http://example.com';
|
|
isCacheFeatureAvailable();
|
|
} catch (error) {
|
|
expect(error).toHaveProperty(
|
|
'message',
|
|
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
|
|
);
|
|
} finally {
|
|
delete process.env['GITHUB_SERVER_URL'];
|
|
}
|
|
});
|
|
|
|
it('isCacheFeatureAvailable disabled on dotcom', () => {
|
|
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false);
|
|
const infoMock = jest.spyOn(core, 'warning');
|
|
const message =
|
|
'The runner was not able to contact the cache service. Caching will be skipped';
|
|
try {
|
|
process.env['GITHUB_SERVER_URL'] = 'http://github.com';
|
|
expect(isCacheFeatureAvailable()).toBe(false);
|
|
expect(infoMock).toHaveBeenCalledWith(message);
|
|
} finally {
|
|
delete process.env['GITHUB_SERVER_URL'];
|
|
}
|
|
});
|
|
|
|
it('isCacheFeatureAvailable is enabled', () => {
|
|
jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => true);
|
|
expect(isCacheFeatureAvailable()).toBe(true);
|
|
});
|
|
});
|