Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* macros.js: Test macros for director tests.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
request = require('request');
11
12
exports.assertGet = function(port, uri, expected) {
13
var context = {
14
topic: function () {
15
request({ uri: 'http://localhost:' + port + '/' + uri }, this.callback);
16
}
17
};
18
19
context['should respond with `' + expected + '`'] = function (err, res, body) {
20
assert.isNull(err);
21
assert.equal(res.statusCode, 200);
22
assert.equal(body, expected);
23
};
24
25
return context;
26
};
27
28
exports.assertPost = function(port, uri, expected) {
29
return {
30
topic: function () {
31
request({
32
method: 'POST',
33
uri: 'http://localhost:' + port + '/' + uri,
34
body: JSON.stringify(expected)
35
}, this.callback);
36
},
37
"should respond with the POST body": function (err, res, body) {
38
assert.isNull(err);
39
assert.equal(res.statusCode, 200);
40
assert.deepEqual(JSON.parse(body), expected);
41
}
42
};
43
};
44
45