renovate/lib/config/env.spec.ts

143 lines
5.1 KiB
TypeScript
Raw Normal View History

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';
describe('config/env', () => {
describe('.getConfig(env)', () => {
it('returns empty env', () => {
expect(env.getConfig({})).toEqual({ hostRules: [] });
});
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);
});
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);
});
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);
});
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']);
});
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']);
});
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');
});
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 = {
GITHUB_COM_TOKEN: 'a github.com token',
RENOVATE_ENDPOINT: 'a ghe endpoint',
RENOVATE_TOKEN: 'a ghe token',
2018-07-06 05:26:36 +00:00
};
expect(env.getConfig(envParam)).toMatchSnapshot();
});
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 = {
RENOVATE_PLATFORM: PLATFORM_TYPE_GITLAB,
RENOVATE_TOKEN: 'a gitlab.com token',
};
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 = {
RENOVATE_PLATFORM: PLATFORM_TYPE_GITLAB,
RENOVATE_TOKEN: 'a gitlab token',
RENOVATE_ENDPOINT: 'a gitlab endpoint',
};
2018-07-06 05:26:36 +00:00
expect(env.getConfig(envParam)).toMatchSnapshot();
});
it('supports Azure DevOps', () => {
2019-08-23 13:46:31 +00:00
const envParam: NodeJS.ProcessEnv = {
RENOVATE_PLATFORM: 'azure',
RENOVATE_TOKEN: 'an Azure DevOps token',
RENOVATE_ENDPOINT: 'an Azure DevOps endpoint',
};
2018-07-06 05:26:36 +00:00
expect(env.getConfig(envParam)).toMatchSnapshot();
});
it('supports docker username/password', () => {
2019-08-23 13:46:31 +00:00
const envParam: NodeJS.ProcessEnv = {
DOCKER_USERNAME: 'some-username',
DOCKER_PASSWORD: 'some-password',
};
expect(env.getConfig(envParam)).toMatchSnapshot();
});
it('supports Bitbucket token', () => {
2019-08-23 13:46:31 +00:00
const envParam: NodeJS.ProcessEnv = {
RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET,
RENOVATE_ENDPOINT: 'a bitbucket endpoint',
RENOVATE_USERNAME: 'some-username',
RENOVATE_PASSWORD: 'app-password',
};
expect(env.getConfig(envParam)).toMatchSnapshot();
});
it('supports Bitbucket username/password', () => {
2019-08-23 13:46:31 +00:00
const envParam: NodeJS.ProcessEnv = {
RENOVATE_PLATFORM: PLATFORM_TYPE_BITBUCKET,
RENOVATE_ENDPOINT: 'a bitbucket endpoint',
RENOVATE_USERNAME: 'some-username',
RENOVATE_PASSWORD: 'app-password',
};
expect(env.getConfig(envParam)).toMatchSnapshot();
});
});
describe('.getEnvName(definition)', () => {
it('returns empty', () => {
2019-08-23 13:46:31 +00:00
const option: Partial<RenovateOptions> = {
name: 'foo',
env: false,
};
expect(env.getEnvName(option)).toEqual('');
});
it('returns existing env', () => {
2019-08-23 13:46:31 +00:00
const option: Partial<RenovateOptions> = {
name: 'foo',
env: 'FOO',
};
expect(env.getEnvName(option)).toEqual('FOO');
});
it('generates RENOVATE_ env', () => {
2019-08-23 13:46:31 +00:00
const option: Partial<RenovateOptions> = {
name: 'oneTwoThree',
};
expect(env.getEnvName(option)).toEqual('RENOVATE_ONE_TWO_THREE');
});
});
});