From f9f530659c0d57aa88cf3c3e52bac300e8cd404c Mon Sep 17 00:00:00 2001 From: Damon Barry Date: Thu, 19 Nov 2015 12:25:28 -0800 Subject: [PATCH] config.host populated from connection string Endpoint --- lib/event_hub_client.js | 6 ++++-- tests/client_creation.js | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/event_hub_client.js b/lib/event_hub_client.js index f668d14..b2438bf 100644 --- a/lib/event_hub_client.js +++ b/lib/event_hub_client.js @@ -11,7 +11,7 @@ function EventHubClient(config) { if (!config.host) throw new ArgumentError('Argument config is missing property host'); } -EventHubClient.fromConnectionString = function (connectionString, path) { +EventHubClient.fromConnectionString = function (connectionString, path, Type_) { if (!connectionString) { throw new ArgumentError('Missing argument connectionString'); } @@ -27,8 +27,10 @@ EventHubClient.fromConnectionString = function (connectionString, path) { var config = { host: host }; + + Type_ = Type_ || EventHubClient; - return new EventHubClient(config); + return new Type_(config); }; EventHubClient.prototype.open = function () { diff --git a/tests/client_creation.js b/tests/client_creation.js index 27b8ac7..06ddaa5 100644 --- a/tests/client_creation.js +++ b/tests/client_creation.js @@ -43,9 +43,16 @@ describe('EventHubClient', function () { }; test.should.throw(ArgumentError, 'Connection string doesn\'t have EntityPath, or missing argument path'); }); + + it('populates config.host from the connection string\'s Endpoint', function () { + function TestClient(config) { this.config = config; } + var client = EventHubClient.fromConnectionString('Endpoint=sb://abc;EntityPath=xyz', null, TestClient); + client.config.should.have.property('host') + .that.equals('abc'); + }); it('creates an EventHubClient from a connection string', function () { - var client = EventHubClient.fromConnectionString('Endpoint=sb://abc;EntityPath=abc'); + var client = EventHubClient.fromConnectionString('Endpoint=sb://abc;EntityPath=xyz'); client.should.be.an.instanceof(EventHubClient); });