node-eventstore-client/test/connection_test.js

101 lines
2.8 KiB
JavaScript
Raw Normal View History

var client = require('../lib/dist');
var GossipSeed = require('../src/gossipSeed');
var testBase = require('./common/base_test');
2018-04-12 16:42:49 +00:00
var withSsl = !!process.env.NODE_ESC_WITH_SSL;
module.exports = {
2018-04-12 16:42:49 +00:00
'Connect To Endpoint Happy Path': function (test) {
test.expect(1);
var tcpEndpoint = {host: 'localhost', port: 1113};
var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint);
conn.connect()
2018-04-12 16:42:49 +00:00
.catch(function (err) {
test.done(err);
});
conn.on('connected', function (endPoint) {
test.areEqual("connected endPoint", endPoint, tcpEndpoint);
done();
});
conn.on('error', done);
function done(err) {
conn.close();
if (err) return test.done(err);
test.done();
}
},
2018-04-12 16:42:49 +00:00
'Connect To Endpoint That Doesn\'t Exist': function (test) {
test.expect(1);
var tcpEndpoint = {host: 'localhost', port: 11112};
2018-04-12 16:42:49 +00:00
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections: 1}), tcpEndpoint);
conn.connect()
2018-04-12 16:42:49 +00:00
.catch(function (err) {
test.done(err);
});
conn.on('connected', function () {
test.ok(false, "Should not be able to connect.");
test.done();
});
conn.on('error', function (err) {
test.done(err);
});
2018-04-12 16:42:49 +00:00
conn.on('closed', function (reason) {
test.ok(reason.indexOf("Reconnection limit reached") === 0, "Wrong expected reason.");
test.done();
});
},
2018-04-12 16:42:49 +00:00
'Create a connection with tcp://host:port string': function (test) {
var conn = client.createConnection({}, 'tcp://localhost:1113');
conn.close();
test.done();
}/*,
'Connect to Cluster using gossip seeds': function (test) {
test.expect(1);
var gossipSeeds = [
new GossipSeed({host: 'localhost', port: 1113}),
new GossipSeed({host: 'localhost', port: 2113}),
new GossipSeed({host: 'localhost', port: 3113})
];
var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds);
conn.connect()
.catch(function(err) {
test.done(err);
});
conn.on('connected', function(endPoint){
test.ok(endPoint, "no endpoint");
done();
});
conn.on('error', done);
function done(err) {
conn.close();
if (err) return test.done(err);
test.done();
}
2018-04-12 16:42:49 +00:00
}*/
};
if (withSsl) {
module.exports['Connect to secure tcp endpoint'] = function(test) {
2018-03-11 22:25:44 +00:00
var conn = client.createConnection({
useSslConnection: true,
targetHost: 'localhost',
validateServer: false
}, 'tcp://localhost:1115');
conn.on('error', function (err) {
test.done(err);
});
conn.connect()
.catch(function (err) {
test.done(err);
});
conn.on('connected', function () {
test.done();
});
}
2018-04-12 16:42:49 +00:00
}
testBase.init(module.exports, false);