forked from artilleryio/artillery-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_capture.js
125 lines (102 loc) · 2.95 KB
/
test_capture.js
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
'use strict';
const test = require('tape');
const runner = require('../lib/runner').runner;
const L = require('lodash');
const csv = require('csv-parse');
const fs = require('fs');
const path = require('path');
let xmlCapture = null;
try {
xmlCapture = require('artillery-xml-capture');
} catch (e) {
}
test('Capture - headers', (t) => {
const fn = './scripts/captures-header.json';
const script = require(fn);
runner(script).then(function(ee) {
ee.on('done', function(report) {
// This will fail if header capture isn't working
t.assert(!report.codes[403], 'No unauthorized responses');
t.assert(report.codes[200] > 0, 'Successful responses');
t.end();
});
ee.run();
});
});
test('Capture - JSON', (t) => {
const fn = './scripts/captures.json';
const script = require(fn);
const data = fs.readFileSync(path.join(__dirname, 'pets.csv'));
csv(data, function(err, parsedData) {
if (err) {
t.fail(err);
}
runner(script, parsedData, {}).then(function(ee) {
ee.on('done', function(report) {
let c200 = report.codes[200];
let c201 = report.codes[201];
let cond = c201 === c200;
t.assert(cond,
'There should be a 200 for every 201');
if (!cond) {
console.log('200: %s; 201: %s', c200, c201);
}
t.end();
});
ee.run();
});
});
});
test('Capture - XML', (t) => {
if (!xmlCapture) {
console.log('artillery-xml-capture does not seem to be installed, skipping XML capture test.');
t.assert(true);
return t.end();
}
const fn = './scripts/captures2.json';
const script = require(fn);
const data = fs.readFileSync(path.join(__dirname, 'pets.csv'));
csv(data, function(err, parsedData) {
if (err) {
t.fail(err);
}
runner(script, parsedData, {}).then(function(ee) {
ee.on('done', function(report) {
t.assert(report.codes[200] > 0, 'Should have a few 200s');
t.assert(report.codes[404] === undefined, 'Should have no 404s');
t.end();
});
ee.run();
});
});
});
test('Capture - Random value from array', (t) => {
const fn = './scripts/captures_array_random.json';
const script = require(fn);
runner(script).then(function(ee) {
ee.on('done', (report) => {
t.assert(report.codes[200] > 0, 'Should have a few 200s');
t.assert(report.codes[404] === undefined, 'Should have no 404s');
t.end();
});
ee.run();
});
});
test('Capture - RegExp', (t) => {
const fn = './scripts/captures-regexp.json';
const script = require(fn);
let ee = runner(script).then(function(ee) {
ee.on('done', (report) => {
let c200 = report.codes[200];
let c201 = report.codes[201];
let cond = c201 === c200;
t.assert(cond,
'There should be a 200 for every 201');
if (!cond) {
console.log('200: %s; 201: %s;', c200, c201);
}
t.end();
});
ee.run();
});
});