Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mock os instead of system
  • Loading branch information
Bryan MacFarlane committed Feb 9, 2020
1 parent 79b62ad commit 241a335
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
24 changes: 12 additions & 12 deletions __tests__/setup-go.test.ts
Expand Up @@ -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');
Expand Down Expand Up @@ -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(() => '');
Expand All @@ -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(() => '');
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -172,15 +172,15 @@ 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);
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');
expect(fileName).toBe('go1.13.7.windows-386.zip');
});
});
15 changes: 4 additions & 11 deletions dist/index.js
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/system.ts
@@ -1,4 +1,4 @@
import * as os from 'os';
let os = require('os');

export function getPlatform(): string {
// darwin and linux match already
Expand All @@ -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;
Expand Down

0 comments on commit 241a335

Please sign in to comment.