Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V dmshib/test cache on ghes #13

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixing tests
  • Loading branch information
dmitry-shibanov committed Mar 31, 2022
commit e69f5fdfa70c7cd7d8fbc60cf7e6693a4ac99a68
36 changes: 18 additions & 18 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,12 @@ jest.mock('@actions/cache');
jest.mock('@actions/core');

describe('isVersionSatisfies', () => {
afterAll(async () => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
});

it.each([
['x', '11.0.0', true],
['3', '3.7.1', true],
@@ -27,32 +33,26 @@ describe('isVersionSatisfies', () => {
});

describe('isCacheFeatureAvailable', () => {
const ORIGINAL_GITHUB_SERVER_URL = process.env['GITHUB_SERVER_URL'];

afterEach(() => {
process.env['GITHUB_SERVER_URL'] = ORIGINAL_GITHUB_SERVER_URL;
});

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'];
}
process.env['GITHUB_SERVER_URL'] = 'http://example.com';
expect(() => isCacheFeatureAvailable()).toThrowError(
'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.');
});

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'];
}
process.env['GITHUB_SERVER_URL'] = 'http://github.com';
expect(isCacheFeatureAvailable()).toBe(false);
expect(infoMock).toHaveBeenCalledWith(message);
});

it('isCacheFeatureAvailable is enabled', () => {