|
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