2022-08-05 09:21:54 +00:00
|
|
|
import _findUp from 'find-up';
|
|
|
|
import upath from 'upath';
|
2022-08-05 05:17:11 +00:00
|
|
|
import { mockExecAll } from '../../../test/exec-util';
|
2022-08-05 09:21:54 +00:00
|
|
|
import { mockedFunction } from '../../../test/util';
|
2022-08-05 05:17:11 +00:00
|
|
|
import { GlobalConfig } from '../../config/global';
|
|
|
|
import { findHermitCwd, getHermitEnvs, isHermit } from './hermit';
|
|
|
|
import type { RawExecOptions } from './types';
|
|
|
|
|
2022-08-05 09:21:54 +00:00
|
|
|
jest.mock('find-up');
|
|
|
|
const findUp = mockedFunction(_findUp);
|
|
|
|
const localDir = '/tmp/renovate/repository/project-a';
|
|
|
|
|
2022-08-05 05:17:11 +00:00
|
|
|
describe('util/exec/hermit', () => {
|
|
|
|
describe('isHermit', () => {
|
|
|
|
it('should return true when binarySource is hermit', () => {
|
|
|
|
GlobalConfig.set({ binarySource: 'docker' });
|
|
|
|
expect(isHermit()).toBeFalse();
|
|
|
|
GlobalConfig.set({ binarySource: 'hermit' });
|
|
|
|
expect(isHermit()).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('findHermitCwd', () => {
|
2022-08-05 09:21:54 +00:00
|
|
|
beforeEach(() => {
|
2022-08-05 05:17:11 +00:00
|
|
|
GlobalConfig.set({ localDir });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should find the closest hermit cwd to the given path', async () => {
|
2022-08-05 09:21:54 +00:00
|
|
|
findUp.mockResolvedValueOnce(upath.join(localDir, 'nested/bin/hermit'));
|
2022-08-05 05:17:11 +00:00
|
|
|
const nestedCwd = 'nested/other/directory';
|
|
|
|
|
|
|
|
expect(await findHermitCwd(nestedCwd)).toBe(`${localDir}/nested/bin`);
|
2022-08-05 09:21:54 +00:00
|
|
|
findUp.mockResolvedValueOnce(upath.join(localDir, 'nested/bin/hermit'));
|
2022-08-05 05:17:11 +00:00
|
|
|
expect(await findHermitCwd('nested')).toBe(`${localDir}/nested/bin`);
|
2022-08-05 09:21:54 +00:00
|
|
|
|
|
|
|
findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit'));
|
2022-08-05 05:17:11 +00:00
|
|
|
expect(await findHermitCwd('')).toBe(`${localDir}/bin`);
|
2022-08-05 09:21:54 +00:00
|
|
|
findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit'));
|
2022-08-05 05:17:11 +00:00
|
|
|
expect(await findHermitCwd('other/directory')).toBe(`${localDir}/bin`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw error when hermit cwd is not found', async () => {
|
|
|
|
const err = new Error('hermit not found for other/directory');
|
|
|
|
|
|
|
|
await expect(findHermitCwd('other/directory')).rejects.toThrow(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getHermitEnvs', () => {
|
2022-08-05 09:21:54 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
GlobalConfig.set({ localDir });
|
|
|
|
});
|
|
|
|
|
2022-08-05 05:17:11 +00:00
|
|
|
it('should return hermit environment variables when hermit env returns successfully', async () => {
|
2022-08-05 09:21:54 +00:00
|
|
|
findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit'));
|
2022-08-05 05:17:11 +00:00
|
|
|
mockExecAll({
|
|
|
|
stdout: `GOBIN=/usr/src/app/repository-a/.hermit/go/bin
|
|
|
|
PATH=/usr/src/app/repository-a/bin
|
|
|
|
`,
|
|
|
|
stderr: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const resp = await getHermitEnvs({} as RawExecOptions);
|
|
|
|
|
|
|
|
expect(resp).toStrictEqual({
|
|
|
|
GOBIN: '/usr/src/app/repository-a/.hermit/go/bin',
|
|
|
|
PATH: '/usr/src/app/repository-a/bin',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|