Added findRubyVersion tests

This commit is contained in:
Derrick Marcey
2019-06-27 14:24:03 -04:00
parent 4fdd5911a6
commit 22cf5cbe54
4 changed files with 64 additions and 7 deletions

View File

@@ -0,0 +1,59 @@
import * as io from '@actions/io';
import fs = require('fs');
import os = require('os');
import path = require('path');
const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');
process.env['RUNNER_TOOLSDIRECTORY'] = toolDir;
process.env['RUNNER_TEMPDIRECTORY'] = tempDir;
import findRubyVersion from '../src/find-ruby';
describe('find-ruby', () => {
beforeAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
});
afterAll(async () => {
try {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
}, 100000);
it('findRubyVersion throws if cannot find any version of ruby', async () => {
let thrown = false;
try {
await findRubyVersion('>= 2.4');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('findRubyVersion throws version of ruby is not complete', async () => {
let thrown = false;
const rubyDir: string = path.join(toolDir, 'Ruby', '2.4.6', os.arch());
await io.mkdirP(rubyDir);
try {
await findRubyVersion('>= 2.4');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('findRubyVersion adds ruby bin to PATH', async () => {
const rubyDir: string = path.join(toolDir, 'Ruby', '2.4.6', os.arch());
await io.mkdirP(rubyDir);
fs.writeFileSync(`${rubyDir}.complete`, 'hello');
await findRubyVersion('>= 2.4');
const binDir = path.join(rubyDir, 'bin');
expect(process.env['PATH']!.startsWith(`${binDir};`)).toBe(true);
});
});

View File

@@ -1,7 +0,0 @@
import findRuby, {Platform} from '../src/find-ruby';
describe('TODO - Add a test suite', () => {
it('TODO - Add a test', async () => {
findRuby({addToPath: 'true', version: '>= 2.4'}, Platform.Windows);
});
});

View File

@@ -15,6 +15,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const tc = __importStar(require("@actions/tool-cache"));
const path = __importStar(require("path"));
@@ -33,6 +34,7 @@ function default_1(version) {
const dest = '/usr/bin/ruby';
exec.exec('sudo ln', ['-sf', path.join(toolPath, 'ruby'), dest]); // replace any existing
}
core.addPath(toolPath);
});
}
exports.default = default_1;

View File

@@ -1,3 +1,4 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import * as path from 'path';
@@ -20,4 +21,6 @@ export default async function(version: string) {
const dest: string = '/usr/bin/ruby';
exec.exec('sudo ln', ['-sf', path.join(toolPath, 'ruby'), dest]); // replace any existing
}
core.addPath(toolPath);
}