UNPKG

9.35 kBJavaScriptView Raw
1var assert = require ('assert');
2var path = require ('path');
3var jobs_manager = require('../lib/job-manager');
4
5describe ('job_manager', function(){
6
7 var packagesLocalFolder = path.join(process.cwd(), "/test/fixtures/packages");
8 var packagesWithInvalidJob = path.join(process.cwd(), "/test/fixtures/package_invalid_job");
9 var packagesWithInvalidDashboard = path.join(process.cwd(), "/test/fixtures/package_invalid_format");
10 var packagesWithNoWidgetField = path.join(process.cwd(), "/test/fixtures/package_dashboard_with_no_widgets");
11 var packagesWithNoLayoutField = path.join(process.cwd(), "/test/fixtures/package_dashboard_with_no_layout");
12 var packagesNoSharedStateForJobs = path.join(process.cwd(), "/test/fixtures/package_job_sharing_state");
13
14 //we use only wallboard local folder, since we don´t want our tests to depend on atlasboard jobs
15 //var packagesAtlasboardFolder = path.join(process.cwd(), "/packages");
16
17 var configPath = path.join(process.cwd(), "/test/fixtures/config");
18 var invalidConfigPath = path.join(process.cwd(), "/test/fixtures/invalid-config");
19 var validJsonWithInvalidFormatConfigPath = path.join(process.cwd(), "/test/fixtures/valid-json-invalid-structure-config");
20 var noExistentConfigPath = path.join(process.cwd(), "/test/fixtures/THIS-PATH-DOES-NOT-EXISTS");
21
22 it('should load dashboard', function(done){
23
24 var options = {
25 packagesPath: [packagesLocalFolder],
26 configPath: configPath
27 };
28
29 jobs_manager.get_jobs(options, function(err, job_workers){
30 assert.ok(!err, err);
31 assert.equal(8, job_workers.length);
32
33 assert.equal(job_workers[0].dashboard_name, "test_dashboard1");
34 assert.equal(job_workers[1].dashboard_name, "test_dashboard1");
35
36 assert.equal(job_workers[2].dashboard_name, "test_dashboard2");
37 assert.equal(job_workers[3].dashboard_name, "test_dashboard2");
38 assert.equal(job_workers[4].dashboard_name, "test_dashboard2");
39
40 assert.equal(job_workers[5].dashboard_name, "other_test_dashboard1");
41 done();
42 });
43 });
44
45 it('should not load filtered dashboards', function(done){
46
47 var options = {
48 packagesPath: [packagesLocalFolder],
49 configPath: configPath,
50 filters: {
51 dashboardFilter: "other_"
52 }
53 };
54
55 jobs_manager.get_jobs(options, function(err, job_workers){
56 assert.ok(!err, err);
57 assert.equal(3, job_workers.length); // 4 job items, 3 valid jobs
58
59 assert.equal(job_workers[0].dashboard_name, "other_test_dashboard1");
60 assert.equal(job_workers[1].dashboard_name, "other_test_dashboards2");
61 assert.equal(job_workers[2].dashboard_name, "other_test_dashboards2");
62 done();
63 });
64 });
65
66 it('should not load filtered jobs', function(done){
67
68 var options = {
69 packagesPath: [packagesLocalFolder],
70 configPath: configPath,
71 filters: {
72 jobFilter: "job1"
73 }
74 };
75
76 jobs_manager.get_jobs(options, function(err, job_workers){
77 assert.ok(!err, err);
78 assert.equal(3, job_workers.length);
79
80 assert.equal(job_workers[0].dashboard_name, "test_dashboard1");
81 assert.equal(job_workers[1].dashboard_name, "test_dashboard2");
82 assert.equal(job_workers[2].dashboard_name, "other_test_dashboards2");
83 done();
84 });
85 });
86
87 it('should be able to get disable widgets', function(done){
88 var options = {
89 packagesPath: [packagesLocalFolder],
90 configPath: configPath
91 };
92
93 jobs_manager.get_jobs(options, function(err, job_workers){
94 assert.ok(!err);
95 var disabled_jobs = job_workers.filter(function(job){ return job.widget_item.enabled;});
96 assert.equal(6, disabled_jobs.length);
97 done();
98 });
99 });
100
101 it('should not return error if invalid dashboard is found since it has been filtered by item manager before', function(done){
102 var options = {
103 packagesPath: [packagesWithInvalidDashboard],
104 configPath: configPath
105 };
106
107 jobs_manager.get_jobs(options, function(err, job_workers){
108 assert.ok(!err);
109 assert.equal(0, job_workers.length);
110 done();
111 });
112 });
113
114 it('should return error if layout field is not found in dashboard file', function(done){
115 var options = {
116 packagesPath: [packagesWithNoLayoutField],
117 configPath: configPath
118 };
119
120 jobs_manager.get_jobs(options, function(err, job_workers){
121 assert.ok(err.indexOf('No layout field found')>-1);
122 done();
123 });
124 });
125
126 it('should return error if widgets field is not found in dashboard file', function(done){
127 var options = {
128 packagesPath: [packagesWithNoWidgetField],
129 configPath: configPath
130 };
131
132 jobs_manager.get_jobs(options, function(err, job_workers){
133 assert.ok(err.indexOf('No widgets field found')>-1);
134 done();
135 });
136 });
137
138 it('should return error if invalid job is found on dashboard', function(done){
139 var options = {
140 packagesPath: [packagesWithInvalidJob],
141 configPath: configPath
142 };
143
144 jobs_manager.get_jobs(options, function(err, job_workers){
145 assert.ok(err);
146 done();
147 });
148 });
149
150 it('should have tasks', function(done){
151 var options = {
152 packagesPath: [packagesLocalFolder],
153 configPath: configPath
154 };
155
156 jobs_manager.get_jobs(options, function(err, job_workers){
157 assert.ok(!err);
158 job_workers.forEach(function(job){
159 assert.ok(typeof job.task === "function" );
160 });
161 done();
162 });
163 });
164
165 it('should have config', function(done){
166 var options = {
167 packagesPath: [packagesLocalFolder],
168 configPath: configPath
169 };
170
171 jobs_manager.get_jobs(options, function(err, job_workers){
172 assert.ok(!err);
173 // job_conf1 is defined in general config file (shared config)
174 // the rest of them are defined in the related dashboard file.
175 job_workers.forEach(function(job){
176 assert.ok(job.config.interval);
177 });
178 done();
179 });
180 });
181
182 it('should be able to extend global config file with custom dashboards properties', function(done){
183 var options = {
184 packagesPath: [packagesLocalFolder],
185 configPath: configPath
186 };
187
188 jobs_manager.get_jobs(options, function(err, job_workers){
189 assert.ok(!err);
190 // job_conf1 should have some properties from the global config files
191 // and other properties from the dashboard file
192 var jobsWithJob1Config = job_workers.filter(function(job){return job.widget_item.config === "job1_conf";});
193
194 assert.equal(3, jobsWithJob1Config.length);
195
196 // test_dasboard1 has aditional "other_configuration_option_to_extend_test_dashboard1" config key
197 assert.ok(jobsWithJob1Config[0].config.interval);
198 assert.ok(jobsWithJob1Config[0].config.other_configuration_option_to_extend_test_dashboard1);
199 assert.ok(!jobsWithJob1Config[0].config.other_configuration_option_to_extend_test_dashboard2);
200
201 // test_dasboard1 has aditional "other_configuration_option_to_extend_test_dashboard2" config key
202 assert.ok(jobsWithJob1Config[1].config.interval);
203 assert.ok(!jobsWithJob1Config[1].config.other_configuration_option_to_extend_test_dashboard1);
204 assert.ok(jobsWithJob1Config[1].config.other_configuration_option_to_extend_test_dashboard2);
205
206 // other_test_dashboard2 doesn´t have any of those
207 assert.ok(jobsWithJob1Config[2].config.interval);
208 assert.ok(!jobsWithJob1Config[2].config.other_configuration_option_to_extend_test_dashboard1);
209 assert.ok(!jobsWithJob1Config[2].config.other_configuration_option_to_extend_test_dashboard2);
210
211 done();
212 });
213 });
214
215 it('should have independent states for each job', function(done){
216 var options = {
217 packagesPath: [packagesNoSharedStateForJobs],
218 configPath: configPath
219 };
220
221 jobs_manager.get_jobs(options, function(err, job_workers){
222 assert.ok(!err, err);
223 assert.equal(2, job_workers.length);
224 job_workers[0].task(null, null, function(err, data){
225 assert.ok(!data);
226 job_workers[1].task(null, null, function(err, data){
227 assert.ok(!data);
228 done();
229 });
230 });
231 });
232 });
233
234 it('should not work with an invalid global config file', function(done){
235 var options = {
236 packagesPath: [packagesNoSharedStateForJobs],
237 configPath: invalidConfigPath
238 };
239
240 jobs_manager.get_jobs(options, function(err, job_workers){
241 assert.ok(err);
242 done();
243 });
244 });
245
246 it('should not work with an global config file with wrong structure', function(done){
247 var options = {
248 packagesPath: [packagesNoSharedStateForJobs],
249 configPath: validJsonWithInvalidFormatConfigPath
250 };
251
252 jobs_manager.get_jobs(options, function(err, job_workers){
253 assert.ok(err);
254 done();
255 });
256 });
257
258 it('should work with no global config file', function(done){
259 var options = {
260 packagesPath: [packagesNoSharedStateForJobs],
261 configPath: noExistentConfigPath
262 };
263
264 jobs_manager.get_jobs(options, function(err, job_workers){
265 assert.ok(!err, err);
266 done();
267 });
268 });
269
270
271});
\No newline at end of file