-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.spec.ts
117 lines (112 loc) · 3.69 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import upath from 'upath';
import { readFile } from '../../../../util/fs';
import getArgv from './__fixtures__/argv';
jest.mock('../../../../datasource/npm');
try {
jest.mock('../../config.js');
} catch (err) {
// file does not exist
}
describe('workers/global/config/parse/index', () => {
describe('.parseConfigs(env, defaultArgv)', () => {
let configParser: typeof import('.');
let defaultArgv: string[];
let defaultEnv: NodeJS.ProcessEnv;
beforeEach(async () => {
jest.resetModules();
configParser = await import('./index');
defaultArgv = getArgv();
defaultEnv = {
RENOVATE_CONFIG_FILE: upath.resolve(
__dirname,
'./__fixtures__/default.js'
),
};
jest.mock('delay', () => Promise.resolve());
});
it('supports token in env', async () => {
const env: NodeJS.ProcessEnv = { ...defaultEnv, RENOVATE_TOKEN: 'abc' };
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([['token', 'abc']]);
});
it('supports token in CLI options', async () => {
defaultArgv = defaultArgv.concat([
'--token=abc',
'--pr-footer=custom',
'--log-context=abc123',
]);
const parsedConfig = await configParser.parseConfigs(
defaultEnv,
defaultArgv
);
expect(parsedConfig).toContainEntries([
['token', 'abc'],
['prFooter', 'custom'],
['logContext', 'abc123'],
]);
});
it('supports forceCli', async () => {
defaultArgv = defaultArgv.concat(['--force-cli=false']);
const env: NodeJS.ProcessEnv = {
...defaultEnv,
RENOVATE_TOKEN: 'abc',
};
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([
['token', 'abc'],
['force', null],
]);
expect(parsedConfig).not.toContainKey('configFile');
});
it('supports config.force', async () => {
const configPath = upath.join(__dirname, '__fixtures__/with-force.js');
const env: NodeJS.ProcessEnv = {
...defaultEnv,
RENOVATE_CONFIG_FILE: configPath,
};
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([
['token', 'abcdefg'],
[
'force',
{
schedule: null,
},
],
]);
});
it('reads private key from file', async () => {
const privateKeyPath = upath.join(__dirname, '__fixtures__/private.pem');
const env: NodeJS.ProcessEnv = {
...defaultEnv,
RENOVATE_PRIVATE_KEY_PATH: privateKeyPath,
};
const expected = await readFile(privateKeyPath);
const parsedConfig = await configParser.parseConfigs(env, defaultArgv);
expect(parsedConfig).toContainEntries([['privateKey', expected]]);
});
it('supports Bitbucket username/password', async () => {
defaultArgv = defaultArgv.concat([
'--platform=bitbucket',
'--username=user',
'--password=pass',
]);
const parsedConfig = await configParser.parseConfigs(
defaultEnv,
defaultArgv
);
expect(parsedConfig).toContainEntries([
['platform', 'bitbucket'],
['username', 'user'],
['password', 'pass'],
]);
});
it('massages trailing slash into endpoint', async () => {
defaultArgv = defaultArgv.concat([
'--endpoint=https://github.renovatebot.com/api/v3',
]);
const parsed = await configParser.parseConfigs(defaultEnv, defaultArgv);
expect(parsed.endpoint).toEqual('https://github.renovatebot.com/api/v3/');
});
});
});