forked from codeleague/codecoach
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.spec.ts
More file actions
140 lines (117 loc) · 4.53 KB
/
Config.spec.ts
File metadata and controls
140 lines (117 loc) · 4.53 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { BuildLogFile } from './@types';
import { ConfigParser } from './Config';
const mockGitHubRepo = 'https://github.com/codeleague/codecoach.git';
const mockGitHubPr = 42;
const mockGitHubToken = 'mockGitHubToken';
const mockGitLabHost = 'https://gitlab.myawesomecompany.com';
const mockGitLabProjectId = 1234;
const mockGitLabMrIid = 69;
const mockGitLabToken = 'mockGitLabToken';
const mockLogType = 'dotnetbuild';
const mockLogFile = './sample/dotnetbuild/build.content';
const mockLogCwd = '/repo/src';
const mockBuildLogFile = `${mockLogType};${mockLogFile};${mockLogCwd}`;
const mockOutput = './tmp/out.json';
const GITHUB_ENV_ARGS = [
'node',
'app.ts',
'--vcs="github"',
`--githubRepoUrl=${mockGitHubRepo}`,
`--githubPr=${mockGitHubPr}`,
`--githubToken=${mockGitHubToken}`,
'--removeOldComment',
`-f=${mockBuildLogFile}`,
`-o=${mockOutput}`,
];
const GITHUB_FILE_ARGS = ['node', 'app.ts', '--config=sample/config/github.json'];
const GITLAB_ENV_ARGS = [
'node',
'app.ts',
'--vcs="gitlab"',
`--gitlabHost=${mockGitLabHost}`,
`--gitlabProjectId=${mockGitLabProjectId}`,
`--gitlabMrIid=${mockGitLabMrIid}`,
`--gitlabToken=${mockGitLabToken}`,
`-f=${mockBuildLogFile}`,
`-o=${mockOutput}`,
'--failOnWarnings',
'--suppressRules',
'RULE1',
'RULE2',
];
const GITLAB_FILE_ARGS = ['node', 'app.ts', '--config=sample/config/gitlab.json'];
const DRYRUN_ENV_ARGS = [
'node',
'app.ts',
`-f=${mockBuildLogFile}`,
`-o=${mockOutput}`,
'--dryRun',
];
const DRYRUN_FILE_ARGS = ['node', 'app.ts', '--config=sample/config/dryrun.json'];
describe('Config parsing Test', () => {
beforeEach(() => {
jest.resetModules();
});
const validateBuildLog = (buildLog: BuildLogFile[]) => {
expect(buildLog).toHaveLength(1);
expect(buildLog[0].type).toBe(mockLogType);
expect(buildLog[0].path).toBe(mockLogFile);
expect(buildLog[0].cwd).toBe(mockLogCwd);
};
it('should be able to parse GitHub config provided by environment variables', async () => {
const config = ConfigParser(GITHUB_ENV_ARGS);
expect(config.vcs).toBe('github');
expect(config.githubRepoUrl).toBe(mockGitHubRepo);
expect(config.githubPr).toBe(mockGitHubPr);
expect(config.githubToken).toBe(mockGitHubToken);
expect(config.removeOldComment).toBe(true);
expect(config.failOnWarnings).toBe(false);
expect(config.suppressRules).toEqual([]);
validateBuildLog(config.buildLogFile);
});
it('should be able to parse GitHub config provided by file', async () => {
const config = ConfigParser(GITHUB_FILE_ARGS);
expect(config.vcs).toBe('github');
expect(config.githubRepoUrl).toBe(mockGitHubRepo);
expect(config.githubPr).toBe(mockGitHubPr);
expect(config.githubToken).toBe(mockGitHubToken);
expect(config.removeOldComment).toBe(false);
expect(config.failOnWarnings).toBe(false);
expect(config.suppressRules).toEqual([]);
validateBuildLog(config.buildLogFile);
});
it('should be able to parse GitLab config provided by environment variables', async () => {
const config = ConfigParser(GITLAB_ENV_ARGS);
expect(config.vcs).toBe('gitlab');
expect(config.gitlabHost).toBe(mockGitLabHost);
expect(config.gitlabProjectId).toBe(mockGitLabProjectId);
expect(config.gitlabMrIid).toBe(mockGitLabMrIid);
expect(config.gitlabToken).toBe(mockGitLabToken);
expect(config.removeOldComment).toBe(false);
expect(config.failOnWarnings).toBe(true);
expect(config.suppressRules).toEqual(['RULE1', 'RULE2']);
validateBuildLog(config.buildLogFile);
});
it('should be able to parse GitLab config provided by file', async () => {
const config = ConfigParser(GITLAB_FILE_ARGS);
expect(config.vcs).toBe('gitlab');
expect(config.gitlabHost).toBe(mockGitLabHost);
expect(config.gitlabProjectId).toBe(mockGitLabProjectId);
expect(config.gitlabMrIid).toBe(mockGitLabMrIid);
expect(config.gitlabToken).toBe(mockGitLabToken);
expect(config.removeOldComment).toBe(true);
expect(config.failOnWarnings).toBe(false);
expect(config.suppressRules).toEqual(['RULE1', 'RULE2']);
validateBuildLog(config.buildLogFile);
});
it('should be able to parse dryRun config provided by environment variables', async () => {
const config = ConfigParser(DRYRUN_ENV_ARGS);
expect(config.dryRun).toBe(true);
validateBuildLog(config.buildLogFile);
});
it('should be able to parse dryRun config provided by file', async () => {
const config = ConfigParser(DRYRUN_FILE_ARGS);
expect(config.dryRun).toBe(true);
validateBuildLog(config.buildLogFile);
});
});