1 | var assert = require('assert');
|
2 |
|
3 | var util = require ('util');
|
4 | var path = require ('path');
|
5 |
|
6 | var baseName = path.basename (__filename, path.extname (__filename));
|
7 |
|
8 | var flow = require ("../flow");
|
9 |
|
10 | var httpi = require ("../initiator/http");
|
11 |
|
12 | var tests = [];
|
13 |
|
14 |
|
15 |
|
16 | var config = require ("./007-http-initiator.json");
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var verbose = false;
|
22 |
|
23 | describe (baseName + " running http initiator tests", function () {
|
24 |
|
25 | var httpDaemon;
|
26 |
|
27 | before (function (done) {
|
28 |
|
29 | httpDaemon = new httpi (config.initiator.http);
|
30 | httpDaemon.on ('ready', done);
|
31 | });
|
32 |
|
33 | after(function() {
|
34 |
|
35 | httpDaemon.server.close();
|
36 | });
|
37 |
|
38 | Object.keys (config.tests).forEach (function (token) {
|
39 | var item = config.tests[token];
|
40 | var method = it;
|
41 |
|
42 | if (typeof testOnly !== "undefined" && testOnly) {
|
43 | if (testOnly === token) {
|
44 | method = it.only;
|
45 | verbose = true;
|
46 | } else {
|
47 | return;
|
48 | }
|
49 | }
|
50 |
|
51 | method (item.description ? item.description + ' ('+token+')' : token, function (done) {
|
52 |
|
53 | var df = new flow ({
|
54 | tasks: item.tasks,
|
55 | templates: config.templates.task,
|
56 | logger: verbose || "VERBOSE" in process.env ? undefined : function () {}
|
57 | }, {
|
58 |
|
59 | initiator: config.initiator
|
60 | });
|
61 |
|
62 | if (!df.ready) {
|
63 | console.log ("dataflow not ready");
|
64 | assert (item.expect === "fail" ? true : false);
|
65 | done ();
|
66 | return;
|
67 | }
|
68 |
|
69 | df.on ('completed', function () {
|
70 | assert (item.expect === "ok" ? true : false);
|
71 | done ();
|
72 | });
|
73 |
|
74 | df.on ('failed', function () {
|
75 | assert (item.expect === "fail" ? true : false);
|
76 | done ();
|
77 | });
|
78 |
|
79 | if (item.autoRun || item.autoRun == void 0)
|
80 | df.run();
|
81 |
|
82 | });
|
83 | });
|
84 | });
|