2020-05-01 16:03:48 +00:00
|
|
|
import * as datasourceDocker from '../datasource/docker';
|
2020-03-05 20:57:24 +00:00
|
|
|
import * as cli from './cli';
|
2020-03-01 06:42:52 +00:00
|
|
|
import getArgv from './config/__fixtures__/argv';
|
2020-03-05 20:57:24 +00:00
|
|
|
import { RenovateOptions } from './definitions';
|
2017-01-20 13:03:18 +00:00
|
|
|
|
|
|
|
describe('config/cli', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
let argv: string[];
|
2017-02-09 04:30:00 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
argv = getArgv();
|
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
describe('.getCliName(definition)', () => {
|
|
|
|
it('generates CLI value', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const option: Partial<RenovateOptions> = {
|
2017-01-20 13:03:18 +00:00
|
|
|
name: 'oneTwoThree',
|
|
|
|
};
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getCliName(option)).toEqual('--one-two-three');
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-01-31 11:19:06 +00:00
|
|
|
it('generates returns empty if CLI false', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const option: Partial<RenovateOptions> = {
|
2017-01-31 11:19:06 +00:00
|
|
|
name: 'oneTwoThree',
|
|
|
|
cli: false,
|
|
|
|
};
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getCliName(option)).toEqual('');
|
2017-01-31 11:19:06 +00:00
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
describe('.getConfig(argv)', () => {
|
|
|
|
it('returns empty argv', () => {
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports boolean no value', () => {
|
|
|
|
argv.push('--recreate-closed');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ recreateClosed: true });
|
2017-01-20 13:03:18 +00:00
|
|
|
argv = argv.slice(0, -1);
|
|
|
|
});
|
|
|
|
it('supports boolean space true', () => {
|
|
|
|
argv.push('--recreate-closed');
|
|
|
|
argv.push('true');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ recreateClosed: true });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2019-03-13 13:58:39 +00:00
|
|
|
it('throws exception for invalid boolean value', () => {
|
|
|
|
argv.push('--recreate-closed');
|
|
|
|
argv.push('badvalue');
|
2019-04-19 20:04:37 +00:00
|
|
|
expect(() => cli.getConfig(argv)).toThrow(
|
|
|
|
Error(
|
|
|
|
"Invalid boolean value: expected 'true' or 'false', but got 'badvalue'"
|
|
|
|
)
|
2019-03-13 13:58:39 +00:00
|
|
|
);
|
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
it('supports boolean space false', () => {
|
|
|
|
argv.push('--recreate-closed');
|
|
|
|
argv.push('false');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ recreateClosed: false });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports boolean equals true', () => {
|
|
|
|
argv.push('--recreate-closed=true');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ recreateClosed: true });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports boolean equals false', () => {
|
|
|
|
argv.push('--recreate-closed=false');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ recreateClosed: false });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports list single', () => {
|
|
|
|
argv.push('--labels=a');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ labels: ['a'] });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports list multiple', () => {
|
|
|
|
argv.push('--labels=a,b,c');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ labels: ['a', 'b', 'c'] });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports string', () => {
|
|
|
|
argv.push('--token=a');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ token: 'a' });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports repositories', () => {
|
|
|
|
argv.push('foo');
|
|
|
|
argv.push('bar');
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({ repositories: ['foo', 'bar'] });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2018-08-31 19:44:40 +00:00
|
|
|
it('parses json lists correctly', () => {
|
|
|
|
argv.push(
|
2020-03-01 07:01:12 +00:00
|
|
|
`--host-rules=[{"domainName":"docker.io","hostType":"${datasourceDocker.id}","username":"user","password":"password"}]`
|
2018-08-31 19:44:40 +00:00
|
|
|
);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2018-09-12 10:16:17 +00:00
|
|
|
hostRules: [
|
2018-08-31 19:44:40 +00:00
|
|
|
{
|
2019-05-24 15:40:39 +00:00
|
|
|
domainName: 'docker.io',
|
2020-03-01 07:01:12 +00:00
|
|
|
hostType: datasourceDocker.id,
|
2018-08-31 19:44:40 +00:00
|
|
|
username: 'user',
|
|
|
|
password: 'password',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
2018-09-12 10:16:17 +00:00
|
|
|
it('parses [] correctly as empty list of hostRules', () => {
|
|
|
|
argv.push(`--host-rules=[]`);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2018-09-12 10:16:17 +00:00
|
|
|
hostRules: [],
|
2018-08-31 19:44:40 +00:00
|
|
|
});
|
|
|
|
});
|
2018-09-12 10:16:17 +00:00
|
|
|
it('parses an empty string correctly as empty list of hostRules', () => {
|
|
|
|
argv.push(`--host-rules=`);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2018-09-12 10:16:17 +00:00
|
|
|
hostRules: [],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('migrates --endpoints', () => {
|
2018-08-31 19:44:40 +00:00
|
|
|
argv.push(`--endpoints=`);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2018-09-12 10:16:17 +00:00
|
|
|
hostRules: [],
|
2018-08-31 19:44:40 +00:00
|
|
|
});
|
|
|
|
});
|
2019-06-11 04:19:05 +00:00
|
|
|
it('parses json object correctly when empty', () => {
|
|
|
|
argv.push(`--onboarding-config=`);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2019-06-11 04:19:05 +00:00
|
|
|
onboardingConfig: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('parses json {} object correctly', () => {
|
|
|
|
argv.push(`--onboarding-config={}`);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2019-06-11 04:19:05 +00:00
|
|
|
onboardingConfig: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('parses json object correctly', () => {
|
|
|
|
argv.push(`--onboarding-config={"extends": ["config:base"]}`);
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(cli.getConfig(argv)).toEqual({
|
2019-06-11 04:19:05 +00:00
|
|
|
onboardingConfig: {
|
|
|
|
extends: ['config:base'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('throws exception for invalid json object', () => {
|
|
|
|
argv.push('--onboarding-config=Hello_World');
|
|
|
|
expect(() => cli.getConfig(argv)).toThrow(
|
|
|
|
Error("Invalid JSON value: 'Hello_World'")
|
|
|
|
);
|
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
});
|