mock os instead of system

This commit is contained in:
Bryan MacFarlane 2020-02-09 18:22:24 -05:00
parent 79b62adb05
commit 241a335117
3 changed files with 20 additions and 27 deletions

View File

@ -26,8 +26,8 @@ describe('setup-go', () => {
findSpy = jest.spyOn(tc, 'find'); findSpy = jest.spyOn(tc, 'find');
inSpy = jest.spyOn(core, 'getInput'); inSpy = jest.spyOn(core, 'getInput');
cnSpy = jest.spyOn(process.stdout, 'write'); cnSpy = jest.spyOn(process.stdout, 'write');
platSpy = jest.spyOn(sys, 'getPlatform'); platSpy = jest.spyOn(os, 'platform');
archSpy = jest.spyOn(sys, 'getArch'); archSpy = jest.spyOn(os, 'arch');
dlSpy = jest.spyOn(tc, 'downloadTool'); dlSpy = jest.spyOn(tc, 'downloadTool');
exSpy = jest.spyOn(tc, 'extractTar'); exSpy = jest.spyOn(tc, 'extractTar');
cacheSpy = jest.spyOn(tc, 'cacheDir'); cacheSpy = jest.spyOn(tc, 'cacheDir');
@ -78,7 +78,7 @@ describe('setup-go', () => {
it('downloads a version not in the cache', async () => { it('downloads a version not in the cache', async () => {
platSpy.mockImplementation(() => 'linux'); platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x64');
inSpy.mockImplementation(() => '1.13.1'); inSpy.mockImplementation(() => '1.13.1');
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@ -97,7 +97,7 @@ describe('setup-go', () => {
it('does not find a version that does not exist', async () => { it('does not find a version that does not exist', async () => {
platSpy.mockImplementation(() => 'linux'); platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x64');
inSpy.mockImplementation(() => '9.99.9'); inSpy.mockImplementation(() => '9.99.9');
findSpy.mockImplementation(() => ''); findSpy.mockImplementation(() => '');
@ -118,8 +118,8 @@ describe('setup-go', () => {
}); });
it('finds stable match for exact version', async () => { it('finds stable match for exact version', async () => {
platSpy.mockImplementation(() => 'windows'); platSpy.mockImplementation(() => 'win32');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x64');
// get request is already mocked // get request is already mocked
// spec: 1.13.7 => 1.13.7 (exact) // spec: 1.13.7 => 1.13.7 (exact)
@ -133,7 +133,7 @@ describe('setup-go', () => {
it('finds stable match for exact dot zero version', async () => { it('finds stable match for exact dot zero version', async () => {
platSpy.mockImplementation(() => 'darwin'); platSpy.mockImplementation(() => 'darwin');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x64');
// spec: 1.13.0 => 1.13 // spec: 1.13.0 => 1.13
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0', true); let match: im.IGoVersion | undefined = await im.findMatch('1.13.0', true);
@ -146,7 +146,7 @@ describe('setup-go', () => {
it('finds latest patch version for minor version spec', async () => { it('finds latest patch version for minor version spec', async () => {
platSpy.mockImplementation(() => 'linux'); platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x64');
core.debug('plat mocks ok'); core.debug('plat mocks ok');
// spec: 1.13 => 1.13.7 (latest) // spec: 1.13 => 1.13.7 (latest)
@ -160,7 +160,7 @@ describe('setup-go', () => {
it('finds latest patch version for caret version spec', async () => { it('finds latest patch version for caret version spec', async () => {
platSpy.mockImplementation(() => 'linux'); platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x64');
// spec: ^1.13.6 => 1.13.7 // spec: ^1.13.6 => 1.13.7
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6', true); let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6', true);
@ -172,8 +172,8 @@ describe('setup-go', () => {
}); });
it('finds latest version for major version spec', async () => { it('finds latest version for major version spec', async () => {
platSpy.mockImplementation(() => 'linux'); platSpy.mockImplementation(() => 'windows');
archSpy.mockImplementation(() => 'amd64'); archSpy.mockImplementation(() => 'x32');
// spec: 1 => 1.13.7 (latest) // spec: 1 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1', true); let match: im.IGoVersion | undefined = await im.findMatch('1', true);
@ -181,6 +181,6 @@ describe('setup-go', () => {
let version: string = match ? match.version : ''; let version: string = match ? match.version : '';
expect(version).toBe('go1.13.7'); expect(version).toBe('go1.13.7');
let fileName = match ? match.files[0].filename : ''; let fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); expect(fileName).toBe('go1.13.7.windows-386.zip');
}); });
}); });

15
dist/index.js vendored
View File

@ -4506,15 +4506,8 @@ module.exports = bytesToUuid;
"use strict"; "use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const os = __importStar(__webpack_require__(87)); let os = __webpack_require__(87);
function getPlatform() { function getPlatform() {
// darwin and linux match already // darwin and linux match already
// freebsd not supported yet but future proofed. // freebsd not supported yet but future proofed.
@ -4536,9 +4529,9 @@ function getArch() {
case 'x64': case 'x64':
arch = 'amd64'; arch = 'amd64';
break; break;
case 'ppc': // case 'ppc':
arch = 'ppc64'; // arch = 'ppc64';
break; // break;
case 'x32': case 'x32':
arch = '386'; arch = '386';
break; break;

View File

@ -1,4 +1,4 @@
import * as os from 'os'; let os = require('os');
export function getPlatform(): string { export function getPlatform(): string {
// darwin and linux match already // darwin and linux match already
@ -25,9 +25,9 @@ export function getArch(): string {
case 'x64': case 'x64':
arch = 'amd64'; arch = 'amd64';
break; break;
case 'ppc': // case 'ppc':
arch = 'ppc64'; // arch = 'ppc64';
break; // break;
case 'x32': case 'x32':
arch = '386'; arch = '386';
break; break;