0
1
Fork 0

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');
inSpy = jest.spyOn(core, 'getInput');
cnSpy = jest.spyOn(process.stdout, 'write');
platSpy = jest.spyOn(sys, 'getPlatform');
archSpy = jest.spyOn(sys, 'getArch');
platSpy = jest.spyOn(os, 'platform');
archSpy = jest.spyOn(os, 'arch');
dlSpy = jest.spyOn(tc, 'downloadTool');
exSpy = jest.spyOn(tc, 'extractTar');
cacheSpy = jest.spyOn(tc, 'cacheDir');
@ -78,7 +78,7 @@ describe('setup-go', () => {
it('downloads a version not in the cache', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64');
archSpy.mockImplementation(() => 'x64');
inSpy.mockImplementation(() => '1.13.1');
findSpy.mockImplementation(() => '');
@ -97,7 +97,7 @@ describe('setup-go', () => {
it('does not find a version that does not exist', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64');
archSpy.mockImplementation(() => 'x64');
inSpy.mockImplementation(() => '9.99.9');
findSpy.mockImplementation(() => '');
@ -118,8 +118,8 @@ describe('setup-go', () => {
});
it('finds stable match for exact version', async () => {
platSpy.mockImplementation(() => 'windows');
archSpy.mockImplementation(() => 'amd64');
platSpy.mockImplementation(() => 'win32');
archSpy.mockImplementation(() => 'x64');
// get request is already mocked
// 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 () => {
platSpy.mockImplementation(() => 'darwin');
archSpy.mockImplementation(() => 'amd64');
archSpy.mockImplementation(() => 'x64');
// spec: 1.13.0 => 1.13
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 () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64');
archSpy.mockImplementation(() => 'x64');
core.debug('plat mocks ok');
// spec: 1.13 => 1.13.7 (latest)
@ -160,7 +160,7 @@ describe('setup-go', () => {
it('finds latest patch version for caret version spec', async () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64');
archSpy.mockImplementation(() => 'x64');
// spec: ^1.13.6 => 1.13.7
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 () => {
platSpy.mockImplementation(() => 'linux');
archSpy.mockImplementation(() => 'amd64');
platSpy.mockImplementation(() => 'windows');
archSpy.mockImplementation(() => 'x32');
// spec: 1 => 1.13.7 (latest)
let match: im.IGoVersion | undefined = await im.findMatch('1', true);
@ -181,6 +181,6 @@ describe('setup-go', () => {
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');
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";
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 });
const os = __importStar(__webpack_require__(87));
let os = __webpack_require__(87);
function getPlatform() {
// darwin and linux match already
// freebsd not supported yet but future proofed.
@ -4536,9 +4529,9 @@ function getArch() {
case 'x64':
arch = 'amd64';
break;
case 'ppc':
arch = 'ppc64';
break;
// case 'ppc':
// arch = 'ppc64';
// break;
case 'x32':
arch = '386';
break;

View File

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