Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update tests
  • Loading branch information
Bryan MacFarlane committed Feb 10, 2020
1 parent 6cb99a3 commit 7d57e56
Showing 1 changed file with 53 additions and 54 deletions.
107 changes: 53 additions & 54 deletions __tests__/setup-go.test.ts
Expand Up @@ -46,14 +46,66 @@ describe('setup-go', () => {

afterAll(async () => {}, 100000);

it('finds stable match for exact dot zero version', async () => {
platSpy.mockImplementation(() => 'darwin');
archSpy.mockImplementation(() => 'x64');

// spec: 1.13.0 => 1.13
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.darwin-amd64.tar.gz');
});

it('finds latest patch version for minor version spec', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'x64');
core.debug('plat mocks ok');

// spec: 1.13 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1.13', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
});

it('finds latest patch version for caret version spec', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'x64');

// spec: ^1.13.6 => 1.13.7
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
});

it('finds latest version for major version spec', async () => {
platSpy.mockImplementation(() => 'windows');
archSpy.mockImplementation(() => 'x32');

// spec: 1 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.windows-386.zip');
});

it('finds a version of go already in the cache', async () => {
inSpy.mockImplementation(() => '1.13.0');
let toolPath = path.normalize('/cache/go/1.13.0/x64');
findSpy.mockImplementation(() => toolPath);
await run();

let expPath = path.join(toolPath, 'bin');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${os.EOL}`);
});

it('finds a version in the cache and adds it to the path', async () => {
Expand Down Expand Up @@ -162,57 +214,4 @@ describe('setup-go', () => {
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.windows-amd64.zip');
});

it('finds stable match for exact dot zero version', async () => {
platSpy.mockImplementation(() => 'darwin');
archSpy.mockImplementation(() => 'x64');

// spec: 1.13.0 => 1.13
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.darwin-amd64.tar.gz');
});

it('finds latest patch version for minor version spec', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'x64');
core.debug('plat mocks ok');

// spec: 1.13 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1.13', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
});

it('finds latest patch version for caret version spec', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'x64');

// spec: ^1.13.6 => 1.13.7
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
});

it('finds latest version for major version spec', async () => {
platSpy.mockImplementation(() => 'windows');
archSpy.mockImplementation(() => 'x32');

// spec: 1 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1', true);
expect(match).toBeDefined();
let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.windows-386.zip');
});
});

0 comments on commit 7d57e56

Please sign in to comment.