Skip to content

Commit

Permalink
test: versionInfo (#1407)
Browse files Browse the repository at this point in the history
* test: `versionInfo`

Add full test coverage resolving the `versionInfo`

* fix: whitespace

* fix: update the test

* fix: just get the test to pass

* fix: substring

---------

Co-authored-by: Tom Hu <thomas.hu@sentry.io>
  • Loading branch information
marcobiedermann and thomasrockhu-codecov committed Jul 16, 2024
1 parent a87fadc commit a06c39c
Showing 1 changed file with 62 additions and 0 deletions.
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');

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'));
});
});

0 comments on commit a06c39c

Please sign in to comment.