forked from amqp-node/amqplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.js
67 lines (56 loc) · 1.89 KB
/
connect.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
'use strict';
var connect = require('../lib/connect').connect;
var assert = require('assert');
var util = require('./util');
var net = require('net');
var fail = util.fail, succeed = util.succeed,
kCallback = util.kCallback;
var URL = process.env.URL || 'amqp://localhost';
suite("Connect API", function() {
test("Connection refused", function(done) {
connect('amqp://localhost:23450', {},
kCallback(fail(done), succeed(done)));
});
// %% this ought to fail the promise, rather than throwing an error
test("bad URL", function() {
assert.throws(function() {
connect('blurble');
});
});
test("wrongly typed open option", function(done) {
var url = require('url');
var parts = url.parse(URL, true);
var q = parts.query || {};
q.frameMax = 'NOT A NUMBER';
parts.query = q;
var u = url.format(parts);
connect(u, {}, kCallback(fail(done), succeed(done)));
});
test("using plain credentials", function(done) {
var url = require('url');
var parts = url.parse(URL, true);
var u = 'guest', p = 'guest';
if (parts.auth) {
var auth = parts.auth.split(":");
u = auth[0], p = auth[1];
}
connect(URL, {credentials: require('../lib/credentials').plain(u, p)},
kCallback(succeed(done), fail(done)));
});
test("using unsupported mechanism", function(done) {
var creds = {
mechanism: 'UNSUPPORTED',
response: function() { return new Buffer(''); }
};
connect(URL, {credentials: creds},
kCallback(fail(done), succeed(done)));
});
test("with a given connection timeout", function(done) {
var timeoutServer = net.createServer(function() {}).listen(31991);
connect('amqp://localhost:31991', {timeout: 50}, function(err, val) {
timeoutServer.close();
if (val) done(new Error('Expected connection timeout, did not'));
else done();
});
});
});