created separate util module

This commit is contained in:
Jared Petersen 2020-05-11 21:10:44 -07:00
parent 1ecbe18c8b
commit 5e3159d960
6 changed files with 145 additions and 42 deletions

View file

@ -17,18 +17,19 @@ jest.mock('@actions/exec', () => {
};
});
const tempDir = path.join(__dirname, 'runner', 'temp');
process.env['RUNNER_TEMP'] = tempDir;
import * as auth from '../src/auth';
const m2Dir = path.join(__dirname, auth.M2_DIR);
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
const tempDir = path.join(__dirname, 'runner', 'temp');
const privateKeyFile = path.join(tempDir, auth.PRIVATE_KEY_FILE);
process.env['RUNNER_TEMP'] = tempDir;
describe('auth tests', () => {
beforeEach(async () => {
await io.rmRF(m2Dir);
await io.mkdirP(tempDir);
}, 300000);
afterAll(async () => {

56
__tests__/util.test.ts Normal file
View file

@ -0,0 +1,56 @@
import path = require('path');
const env = process.env;
describe('util tests', () => {
beforeEach(() => {
process.env = Object.assign({}, env);
Object.defineProperty(process, 'platform', {value: 'linux'});
});
describe('getTempDir', () => {
it('gets temp dir using env', () => {
process.env['RUNNER_TEMP'] = 'defaulttmp'
const util = require('../src/util');
const tempDir = util.getTempDir();
expect(tempDir).toEqual(process.env['RUNNER_TEMP']);
});
it('gets temp dir for windows using userprofile', () => {
Object.defineProperty(process, 'platform', {value: 'win32'});
process.env['USERPROFILE'] = 'winusertmp';
const util = require('../src/util');
const tempDir = util.getTempDir();
expect(tempDir).toEqual(path.join(process.env['USERPROFILE'], 'actions', 'temp'));
});
it('gets temp dir for windows using c drive', () => {
Object.defineProperty(process, 'platform', {value: 'win32'});
const util = require('../src/util');
const tempDir = util.getTempDir();
expect(tempDir).toEqual(path.join('C:\\', 'actions', 'temp'));
});
it('gets temp dir for mac', () => {
Object.defineProperty(process, 'platform', {value: 'darwin'});
const util = require('../src/util');
const tempDir = util.getTempDir();
expect(tempDir).toEqual(path.join('/Users', 'actions', 'temp'));
});
it('gets temp dir for linux', () => {
const util = require('../src/util');
const tempDir = util.getTempDir();
expect(tempDir).toEqual(path.join('/home', 'actions', 'temp'));
});
});
});