2020-01-17 07:26:42 +00:00
|
|
|
import {
|
|
|
|
PLATFORM_TYPE_BITBUCKET,
|
|
|
|
PLATFORM_TYPE_GITLAB,
|
2020-03-05 20:57:24 +00:00
|
|
|
} from '../constants/platforms';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { RenovateOptions } from './definitions';
|
|
|
|
import * as env from './env';
|
2017-01-20 13:03:18 +00:00
|
|
|
|
|
|
|
describe('config/env', () => {
|
|
|
|
describe('.getConfig(env)', () => {
|
|
|
|
it('returns empty env', () => {
|
2018-09-12 10:16:17 +00:00
|
|
|
expect(env.getConfig({})).toEqual({ hostRules: [] });
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports boolean true', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = { RENOVATE_RECREATE_CLOSED: 'true' };
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).recreateClosed).toBe(true);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports boolean false', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = { RENOVATE_RECREATE_CLOSED: 'false' };
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).recreateClosed).toBe(false);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports boolean nonsense as false', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = { RENOVATE_RECREATE_CLOSED: 'foo' };
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).recreateClosed).toBe(false);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
delete process.env.RENOVATE_RECREATE_CLOSED;
|
|
|
|
it('supports list single', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = { RENOVATE_LABELS: 'a' };
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).labels).toEqual(['a']);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports list multiple', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = { RENOVATE_LABELS: 'a,b,c' };
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).labels).toEqual(['a', 'b', 'c']);
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('supports string', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = { RENOVATE_TOKEN: 'a' };
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).token).toBe('a');
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
2017-07-24 18:56:15 +00:00
|
|
|
it('supports json', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
RENOVATE_LOCK_FILE_MAINTENANCE: '{}',
|
|
|
|
};
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam).lockFileMaintenance).toEqual({});
|
|
|
|
});
|
|
|
|
it('supports GitHub token', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
RENOVATE_TOKEN: 'github.com token',
|
|
|
|
};
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('supports GitHub custom endpoint', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
RENOVATE_ENDPOINT: 'a ghe endpoint',
|
|
|
|
};
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('supports GitHub custom endpoint and github.com', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2018-07-12 12:10:19 +00:00
|
|
|
GITHUB_COM_TOKEN: 'a github.com token',
|
2019-01-14 06:53:42 +00:00
|
|
|
RENOVATE_ENDPOINT: 'a ghe endpoint',
|
|
|
|
RENOVATE_TOKEN: 'a ghe token',
|
2018-07-06 05:26:36 +00:00
|
|
|
};
|
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
2020-05-28 10:56:17 +00:00
|
|
|
it('supports GitHub custom endpoint and gitlab.com', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
RENOVATE_ENDPOINT: 'a ghe endpoint',
|
|
|
|
RENOVATE_TOKEN: 'a ghe token',
|
|
|
|
};
|
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
2018-07-06 05:26:36 +00:00
|
|
|
it('supports GitLab token', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2020-01-17 07:26:42 +00:00
|
|
|
RENOVATE_PLATFORM: PLATFORM_TYPE_GITLAB,
|
2019-01-14 06:53:42 +00:00
|
|
|
RENOVATE_TOKEN: 'a gitlab.com token',
|
2018-07-12 12:10:19 +00:00
|
|
|
};
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('supports GitLab custom endpoint', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2020-01-17 07:26:42 +00:00
|
|
|
RENOVATE_PLATFORM: PLATFORM_TYPE_GITLAB,
|
2019-01-14 06:53:42 +00:00
|
|
|
RENOVATE_TOKEN: 'a gitlab token',
|
|
|
|
RENOVATE_ENDPOINT: 'a gitlab endpoint',
|
2018-07-12 12:10:19 +00:00
|
|
|
};
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
2019-01-14 14:22:24 +00:00
|
|
|
it('supports Azure DevOps', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2019-01-14 14:22:24 +00:00
|
|
|
RENOVATE_PLATFORM: 'azure',
|
|
|
|
RENOVATE_TOKEN: 'an Azure DevOps token',
|
|
|
|
RENOVATE_ENDPOINT: 'an Azure DevOps endpoint',
|
2018-07-12 12:10:19 +00:00
|
|
|
};
|
2018-07-06 05:26:36 +00:00
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
2017-07-24 18:56:15 +00:00
|
|
|
});
|
2018-08-05 05:39:38 +00:00
|
|
|
it('supports docker username/password', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2018-08-05 05:39:38 +00:00
|
|
|
DOCKER_USERNAME: 'some-username',
|
|
|
|
DOCKER_PASSWORD: 'some-password',
|
|
|
|
};
|
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
2018-08-29 05:30:03 +00:00
|
|
|
it('supports Bitbucket token', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2020-01-17 07:26:42 +00:00
|
|
|
RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET,
|
2019-01-14 06:53:42 +00:00
|
|
|
RENOVATE_ENDPOINT: 'a bitbucket endpoint',
|
|
|
|
RENOVATE_USERNAME: 'some-username',
|
|
|
|
RENOVATE_PASSWORD: 'app-password',
|
2018-08-29 05:30:03 +00:00
|
|
|
};
|
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('supports Bitbucket username/password', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
2020-01-17 07:26:42 +00:00
|
|
|
RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET,
|
2019-01-14 06:53:42 +00:00
|
|
|
RENOVATE_ENDPOINT: 'a bitbucket endpoint',
|
|
|
|
RENOVATE_USERNAME: 'some-username',
|
|
|
|
RENOVATE_PASSWORD: 'app-password',
|
2018-08-29 05:30:03 +00:00
|
|
|
};
|
|
|
|
expect(env.getConfig(envParam)).toMatchSnapshot();
|
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
describe('.getEnvName(definition)', () => {
|
2017-01-31 11:19:06 +00:00
|
|
|
it('returns empty', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const option: Partial<RenovateOptions> = {
|
2017-01-31 11:19:06 +00:00
|
|
|
name: 'foo',
|
|
|
|
env: false,
|
|
|
|
};
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(env.getEnvName(option)).toEqual('');
|
2017-01-31 11:19:06 +00:00
|
|
|
});
|
2017-01-20 13:03:18 +00:00
|
|
|
it('returns existing env', () => {
|
2019-08-23 13:46:31 +00:00
|
|
|
const option: Partial<RenovateOptions> = {
|
2017-01-20 13:03:18 +00:00
|
|
|
name: 'foo',
|
|
|
|
env: 'FOO',
|
|
|
|
};
|
2019-09-25 09:40:58 +00:00
|
|
|
expect(env.getEnvName(option)).toEqual('FOO');
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
it('generates RENOVATE_ env', () => {
|
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(env.getEnvName(option)).toEqual('RENOVATE_ONE_TWO_THREE');
|
2017-01-20 13:03:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|