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

test: versionInfo #1407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32351,12 +32351,12 @@ const isPullRequestFromFork = () => {
return (baseLabel.split(':')[0] !== headLabel.split(':')[0]);
};
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
if (isPullRequestFromFork()) {
let token = core.getInput('token');
if (!token && isPullRequestFromFork()) {
core.info('==> Fork detected, tokenless uploading used');
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
return Promise.resolve('');
}
let token = core.getInput('token');
let url = core.getInput('url');
const useOIDC = isTrue(core.getInput('use_oidc'));
if (useOIDC) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions src/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as core from '@actions/core';
import {Agent, MockAgent, setGlobalDispatcher} from 'undici';

import versionInfo from './version';

const mockAgent = new MockAgent();

beforeAll(() => {
setGlobalDispatcher(mockAgent);
mockAgent.disableNetConnect();
});

afterEach(() => {
jest.clearAllMocks();
});

afterAll(async () => {
await mockAgent.close();
setGlobalDispatcher(new Agent());
});

describe('versionInfo', () => {
const platform = 'linux';

test('should resolve requested version info', async () => {
const version = 'latest';
const coreInfoSpy = jest.spyOn(core, 'info');

mockAgent
.get('https://cli.codecov.io')
.intercept({
path: `/${platform}/${version}`,
})
.reply(200, {
version: 'v0.5.2',
});

await versionInfo(platform, version);

expect(coreInfoSpy).toHaveBeenCalledTimes(2);
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version latest');
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version v0.5.2');
});

test('should handle unsupported version', async () => {
const version = 'unsupported';
const coreInfoSpy = jest.spyOn(core, 'info');

mockAgent
.get('https://cli.codecov.io')
.intercept({
path: `/${platform}/${version}`,
})
.reply(404, 'MESSAGE');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any arbitrary message would work as the service returns XML, which can not be parsed by the .json() method


await versionInfo(platform, version);

expect(coreInfoSpy).toHaveBeenCalledTimes(2);
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version unsupported');
expect(coreInfoSpy).toHaveBeenCalledWith(expect.stringContaining('Could not pull latest version information'));
});
});
Loading