Files
setup-ruby/__tests__/find-ruby.test.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-06-27 14:24:03 -04:00
import * as io from '@actions/io';
import fs = require('fs');
import os = require('os');
import path = require('path');
2019-07-15 14:26:50 -04:00
const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');
2019-06-27 14:24:03 -04:00
2019-07-15 13:45:00 -04:00
process.env['AGENT_TOOLSDIRECTORY'] = toolDir;
process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;
2019-06-27 14:24:03 -04:00
2019-07-15 13:23:24 -04:00
import {findRubyVersion} from '../src/installer';
2019-06-27 14:24:03 -04:00
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);
2019-07-15 13:45:00 -04:00
it('Uses version of ruby installed in cache', async () => {
const rubyDir: string = path.join(toolDir, 'Ruby', '17.0.0', os.arch());
await io.mkdirP(rubyDir);
fs.writeFileSync(`${rubyDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await findRubyVersion('17.0.0');
2019-06-27 14:24:03 -04:00
});
2019-07-15 13:45:00 -04:00
it('findRubyVersion throws if cannot find any version of ruby', async () => {
2019-06-27 14:24:03 -04:00
let thrown = false;
try {
2019-07-15 13:45:00 -04:00
await findRubyVersion('9.9.9');
2019-06-27 14:24:03 -04:00
} 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');
2019-07-15 13:23:24 -04:00
await findRubyVersion('2.4.6');
2019-06-27 14:24:03 -04:00
const binDir = path.join(rubyDir, 'bin');
2019-07-15 13:56:32 -04:00
console.log(`binDir: ${binDir}`);
2019-07-15 13:45:00 -04:00
console.log(`PATH: ${process.env['PATH']}`);
2019-07-15 13:59:52 -04:00
expect(process.env['PATH']!.startsWith(`${binDir}`)).toBe(true);
2019-06-27 14:24:03 -04:00
});
});