UNPKG

1.42 kBJavaScriptView Raw
1var assert = require('assert');
2
3function validateTask(task, notRunning, notWriteable, unsuccessful) {
4 /*
5 id: "c57579f3-af61-47cb-b803-10527b776c89",
6 pid: 8302,
7 startTime: 1433775287309,
8 running: true,
9 writable: true,
10 errors: []
11 */
12 var testedAttrs = {};
13
14 assert.equal(typeof task, 'object');
15
16 assert.equal(typeof task.id, 'string');
17 assert(/^[0-9a-z\-]{36}$/.test(task.id));
18 testedAttrs.id = true;
19
20 assert.equal(typeof task.pid, 'number');
21 assert(task.pid > 1);
22 testedAttrs.pid = true;
23
24 assert.equal(typeof task.startTime, 'number');
25 assert(Date.now() >= task.startTime);
26 testedAttrs.startTime = true;
27
28 assert.strictEqual(task.running, !notRunning);
29 testedAttrs.running = true;
30
31 assert.strictEqual(task.writable, !(notRunning || notWriteable));
32 testedAttrs.writable = true;
33
34 assert.deepEqual(task.errors, []);
35 testedAttrs.errors = true;
36
37 if (notRunning) {
38 if (unsuccessful) {
39 assert.notEqual(task.code, 0);
40 assert.notEqual(task.signal, null);
41 } else {
42 assert.equal(task.code, 0);
43 assert.equal(task.signal, null);
44 }
45 testedAttrs.code = true;
46 testedAttrs.signal = true;
47 }
48
49 if (task.hasOwnProperty('timeout')) {
50 assert.equal(typeof task.timeout, 'number');
51 testedAttrs.timeout = true;
52 }
53
54 assert.deepEqual(Object.keys(task).sort(), Object.keys(testedAttrs).sort());
55}
56
57module.exports = validateTask;