Skip to content

Commit 2bcfa73

Browse files
committed
[test] First pass at mocha based multi-provider tests
1 parent dab2066 commit 2bcfa73

14 files changed

Lines changed: 433 additions & 279 deletions

File tree

lib/pkgcloud/amazon/compute/client/servers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ var async = require('async'),
1818
// Gets the current API version
1919
//
2020
exports.getVersion = function getVersion(callback) {
21-
callback(null, this.version);
21+
var self = this;
22+
process.nextTick(function() {
23+
callback(null, self.version);
24+
});
2225
};
2326

2427
//

lib/pkgcloud/core/base/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Client.prototype._doRequest = function (options, callback) {
9595

9696
opts.uri = options.uri || self.getUrl(options);
9797

98-
// console.log((opts.method ? opts.method : 'GET') + ': ' + opts.uri + (opts.qs ? '?' + qs.encode(opts.qs) : ''));
98+
// console.log((self.authorized ? 'Y ' : 'N ') + (opts.method ? opts.method : 'GET') + ': ' + opts.uri + (opts.qs ? '?' + qs.encode(opts.qs) : ''));
9999

100100
delete opts.path;
101101

test/common/base/client-test.js

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,83 @@
1-
//// if one of the befores blows up should return in err back
2-
//// if one of the befores blows up no callback returns in stream
3-
//// should be able to sign appropriately
4-
///*
5-
// * client.js: Tests for pkgcloud Joyent compute image requests
6-
// *
7-
// * (C) 2012 Nodejitsu Inc.
8-
// *
9-
// */
10-
//
11-
//var vows = require('vows'),
12-
// assert = require('../../helpers/assert'),
13-
// Client = new require('../../../lib/pkgcloud/core/base/client').Client;
14-
//
15-
//vows.describe('pkgcloud/core/base/client').addBatch({
16-
// "The pkgcloud base client": {
17-
// "the request() method": {
18-
// "with a wrong request with a cb": {
19-
// topic: function () {
20-
// var cli = new Client();
21-
// cli.getUrl = function () { return "badurl"; };
22-
// cli.failCodes = {};
23-
// cli.request({ path: '/' }, this.callback);
24-
// },
25-
// "should return the error on the cb": function (err, response) {
26-
// assert.assertError(err);
27-
// }
28-
// },
29-
// "with a wrong request without a cb": {
30-
// topic: function () {
31-
// var self = this,
32-
// cli = new Client();
33-
//
34-
// cli.getUrl = function () { return "badurl"; };
35-
// cli.failCodes = {};
36-
// var stream = cli.request({ path: '/' });
37-
// stream.on('error', function () { return self.callback(null, true); });
38-
// stream.on('end', function () { return self.callback(null, false); });
39-
// },
40-
// "should return the error on the EE": function (_, ok) {
41-
// assert.ok(ok);
42-
// }
43-
// }
44-
// },
45-
// "the before filters": {
46-
// "throwing an error with a cb": {
47-
// topic: function () {
48-
// var cli = new Client();
49-
// cli.getUrl = function () { return "badurl"; };
50-
// cli.failCodes = {};
51-
// cli.before = [function () { throw new Error('Foo!'); }];
52-
// cli.request('/', this.callback, this.callback);
53-
// },
54-
// "should return the error on the cb": function (err, response) {
55-
// assert.ok(err.message);
56-
// assert.equal(err.message, "Foo!");
57-
// }
58-
// },
59-
// "throwing an error without a cb": {
60-
// topic: function () {
61-
// var self = this,
62-
// cli = new Client();
63-
//
64-
// cli.getUrl = function () { return "badurl"; };
65-
// cli.failCodes = {};
66-
// var stream = cli.request({ path: '/' });
67-
// stream.on('error', function () { return self.callback(null, true); });
68-
// stream.on('end', function () { return self.callback(null, false); });
69-
// },
70-
// "should return the error on the EE": function (_, ok) {
71-
// assert.ok(ok);
72-
// }
73-
// }
74-
// }
75-
// }
76-
//})["export"](module);
1+
/*
2+
* client-test.js: Tests for pkgcloud base client
3+
*
4+
* (C) 2012 Nodejitsu Inc.
5+
*
6+
*/
7+
8+
var should = require('should'),
9+
Client = new require('../../../lib/pkgcloud/core/base/client').Client;
10+
11+
describe('pkgcloud/core/base/client', function () {
12+
describe('The pkgcloud base client request method', function() {
13+
it('with a wrong request with a cb', function(done) {
14+
var cli = new Client();
15+
cli.getUrl = function () {
16+
return "badurl";
17+
};
18+
cli.failCodes = {};
19+
cli.request({ path: '/' }, function(err) {
20+
should.exist(err);
21+
done();
22+
});
23+
});
24+
25+
it('with a wrong request without a cb', function (done) {
26+
var cli = new Client();
27+
28+
cli.getUrl = function () {
29+
return "badurl";
30+
};
31+
cli.failCodes = {};
32+
var stream = cli.request({ path: '/' });
33+
stream.on('error', function () {
34+
return handleResponse(true);
35+
});
36+
stream.on('end', function () {
37+
return handleResponse(false);
38+
});
39+
40+
function handleResponse(err) {
41+
should.exist(err);
42+
done();
43+
}
44+
45+
});
46+
47+
it('the before filters throwing an error with a callback should return the error on the cb', function(done) {
48+
var cli = new Client();
49+
cli.getUrl = function () {
50+
return "badurl";
51+
};
52+
cli.failCodes = {};
53+
cli.before = [function () {
54+
throw new Error('Foo!');
55+
}];
56+
cli.request({ path: '/' }, function(err) {
57+
should.exist(err);
58+
done();
59+
});
60+
});
61+
62+
it('the before filters throwing an error without a callback should return the error on the EE', function(done) {
63+
var cli = new Client();
64+
65+
cli.getUrl = function () {
66+
return "badurl";
67+
};
68+
cli.failCodes = {};
69+
var stream = cli.request({ path: '/' });
70+
stream.on('error', function () {
71+
handleResponse(true);
72+
});
73+
stream.on('end', function () {
74+
handleResponse(false);
75+
});
76+
77+
function handleResponse(err) {
78+
should.exist(err);
79+
done();
80+
}
81+
});
82+
});
83+
});

0 commit comments

Comments
 (0)