Fix #324
Added support for string hosts in ConnectionAbstract constructor. Host constructor is used with supplied host string to create host object for ConnectionAbstract.
This commit is contained in:
@ -22,6 +22,8 @@ function ConnectionAbstract(host, config) {
|
|||||||
throw new TypeError('Missing host');
|
throw new TypeError('Missing host');
|
||||||
} else if (host instanceof Host) {
|
} else if (host instanceof Host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
} else if (typeof host === "string"){
|
||||||
|
this.host = new Host(host);
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError('Invalid host');
|
throw new TypeError('Invalid host');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,15 @@ describe('Connection Abstract', function () {
|
|||||||
expect(conn.host).to.be(host);
|
expect(conn.host).to.be(host);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('constructs with string host using Host constructor', function(){
|
||||||
|
var host = 'localhost';
|
||||||
|
var port = 9200;
|
||||||
|
var hostUrl = host+':'+port;
|
||||||
|
var conn = new ConnectionAbstract(hostUrl);
|
||||||
|
expect(conn.host.host).to.be(host);
|
||||||
|
expect(conn.host.port).to.be(port);
|
||||||
|
});
|
||||||
|
|
||||||
it('requires a valid host', function () {
|
it('requires a valid host', function () {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
new ConnectionAbstract();
|
new ConnectionAbstract();
|
||||||
|
|||||||
Reference in New Issue
Block a user