Skip to content

Commit f13cdb9

Browse files
committed
moving buster tests to test-buster dir
1 parent b053860 commit f13cdb9

File tree

8 files changed

+179
-3
lines changed

8 files changed

+179
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ lint:
3131
./node_modules/jshint/bin/hint ./lib --config $(BASE)/.jshintrc && cd test && ../node_modules/jshint/bin/hint . && cd ..
3232

3333

34-
.PHONY: test docs
34+
.PHONY: test test-buster

test/buster.js renamed to buster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ var config = module.exports;
33
config["Buster tests"] = {
44
environment: "node",
55
tests: [
6-
"**/buster/**/*unit.js"
6+
"test-buster/**/*unit.js"
77
]
88
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buster.spec.expose(); // Make spec functions global
33
var assert = buster.assert;
44

55
var restify = require('restify');
6-
var support = require('../../../support');
6+
var support = require('../../support');
77
var http = support.http;
88
var User = main.models.User;
99

test-buster/support/http.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
var restify = require('restify');
2+
var util = require('util');
3+
var host = process.env.HOST || 'localhost';
4+
var port = process.env.PORT;
5+
var ENV = process.env.NODE_ENV;
6+
7+
if (!port) {
8+
if (host === 'localhost') {
9+
port = '8080';
10+
} else {
11+
port = '80';
12+
}
13+
}
14+
15+
function TestServer(args) {
16+
this.routes = args.routes;
17+
this.server = restify.createServer();
18+
this.server.use(restify.bodyParser());
19+
this.server.use(restify.queryParser());
20+
main.server.router.register_routes(this.server, this.routes);
21+
}
22+
23+
TestServer.prototype.start = function () {
24+
if (this.server) {
25+
this.server.listen(port, host);
26+
} else {
27+
throw new Error('Server not found');
28+
}
29+
};
30+
31+
TestServer.prototype.stop = function () {
32+
this.server.close();
33+
};
34+
35+
function HttpClient(args) {
36+
args = args || {};
37+
if (!args.host) {
38+
throw new Error('HTTP Client requires a host param');
39+
}
40+
41+
this.host = args.host;
42+
this.protocol = args.protocol || 'http';
43+
this.port = args.port;
44+
this.url = 'http://' + this.host + ':' + this.port;
45+
46+
//this.client = restify.createStringClient({url: this.url});
47+
this.client = restify.createJsonClient({url: this.url});
48+
}
49+
50+
HttpClient.prototype.get = function (path_or_options, cb) {
51+
this.client.get(path_or_options, function (err, req, res, data) {
52+
cb(err, data, res, req);
53+
});
54+
};
55+
56+
HttpClient.prototype.post = function (path_or_options, body, cb) {
57+
this.client.post(path_or_options, body, function (err, req, res, data) {
58+
cb(err, data, res, req);
59+
});
60+
};
61+
62+
HttpClient.prototype.put = function (path_or_options, body, cb) {
63+
this.client.put(path_or_options, body, function (err, req, res, data) {
64+
cb(err, data, res, req);
65+
});
66+
};
67+
68+
HttpClient.prototype.del = function (path_or_options, cb) {
69+
this.client.del(path_or_options, function (err, req, res, data) {
70+
cb(err, data, res, req);
71+
});
72+
};
73+
74+
var http = {
75+
client: function () {
76+
return new HttpClient({host: host, port: port});
77+
},
78+
79+
server: {
80+
create: function (routes) {
81+
return new TestServer({routes: routes});
82+
}
83+
},
84+
85+
host: host,
86+
port: port
87+
};
88+
89+
module.exports = http;
90+

test-buster/support/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require('../../lib');
2+
3+
module.exports = {
4+
http: require('./http'),
5+
random: require('./random'),
6+
walk_dir: require('./walk_dir'),
7+
8+
shallow_clone: function (object) {
9+
var ret = {};
10+
if (object) {
11+
Object.keys(object).forEach(function (val) {
12+
ret[val] = object[val];
13+
});
14+
}
15+
return ret;
16+
},
17+
};

test-buster/support/random.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var Faker = require('Faker');
2+
3+
var random = {
4+
number: function (max) {
5+
max = max || 10000;
6+
return Faker.Helpers.randomNumber(max);
7+
},
8+
9+
string: function (str_len) {
10+
str_len = str_len || 8;
11+
var chars = "abcdefghiklmnopqrstuvwxyz";
12+
var random_str = '';
13+
for (var i = 0; i < str_len; i++) {
14+
var rnum = Math.floor(Math.random() * chars.length);
15+
random_str += chars.substring(rnum, rnum + 1);
16+
}
17+
return random_str;
18+
},
19+
20+
email: function () {
21+
return this.string() + '+' + this.string() + '@' + 'example.com';
22+
}
23+
};
24+
25+
module.exports = random;

test-buster/support/walk_dir.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var fs = require('fs');
2+
3+
var methods = {
4+
walk: function (dir, validation_function, cb) {
5+
if (arguments.length === 2) {
6+
cb = validation_function;
7+
validation_function = null;
8+
}
9+
10+
var results = [];
11+
fs.readdir(dir, function (err, list) {
12+
if (err) { return cb(err); }
13+
14+
var pending = list.length;
15+
16+
if (!pending) { return cb(null, results); }
17+
18+
list.forEach(function (file) {
19+
file = dir + '/' + file;
20+
fs.stat(file, function (err, stat) {
21+
if (stat && stat.isDirectory()) {
22+
methods.walk(file, validation_function, function (err, res) {
23+
results = results.concat(res);
24+
if (!--pending) { cb(null, results); }
25+
});
26+
} else {
27+
if (typeof validation_function === 'function') {
28+
if (validation_function(file)) {
29+
results.push(file);
30+
}
31+
} else {
32+
results.push(file);
33+
}
34+
35+
if (!--pending) { cb(null, results); }
36+
}
37+
});
38+
});
39+
});
40+
}
41+
};
42+
43+
module.exports = methods;

test/support/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require('../../lib');
2+
23
module.exports = {
34
http: require('./http'),
45
random: require('./random'),

0 commit comments

Comments
 (0)