Client ctor takes config object with host property
This commit is contained in:
Родитель
0eb3035f1d
Коммит
1d32a9aa1e
|
@ -7,7 +7,9 @@ var Promise = require('bluebird');
|
|||
var ArgumentError = require('azure-iot-common').errors.ArgumentError;
|
||||
var ConnectionString = require('azure-iot-common').ConnectionString;
|
||||
|
||||
function EventHubClient() {}
|
||||
function EventHubClient(config) {
|
||||
if (!config.host) throw new ArgumentError('Argument config is missing property host');
|
||||
}
|
||||
|
||||
EventHubClient.fromConnectionString = function (connectionString, path) {
|
||||
if (!connectionString) {
|
||||
|
@ -18,8 +20,15 @@ EventHubClient.fromConnectionString = function (connectionString, path) {
|
|||
if (!cn.EntityPath && !path) {
|
||||
throw new ArgumentError('Connection string doesn\'t have EntityPath, or missing argument path');
|
||||
}
|
||||
|
||||
var endpoint = cn.Endpoint || '';
|
||||
var host = (endpoint.match('sb://([^/]*)') || [])[1];
|
||||
|
||||
var config = {
|
||||
host: host
|
||||
};
|
||||
|
||||
return new EventHubClient();
|
||||
return new EventHubClient(config);
|
||||
};
|
||||
|
||||
EventHubClient.prototype.open = function () {
|
||||
|
|
13
tasks
13
tasks
|
@ -0,0 +1,13 @@
|
|||
azure-eventhubs
|
||||
Client
|
||||
+ .fromConnectionString
|
||||
#open/close
|
||||
#getPartitionIds
|
||||
#createReceiver
|
||||
|
||||
Receiver
|
||||
emits: errorReceived
|
||||
emits: message
|
||||
|
||||
* put chai setup in a common fixture instead of dupicating it in every test file
|
||||
* expose EventHubClient as azure-eventhubs.Client
|
|
@ -16,6 +16,17 @@ function testFalsyValues(testFn) {
|
|||
}
|
||||
|
||||
describe('EventHubClient', function () {
|
||||
describe('#constructor', function () {
|
||||
it('throws if config.host is falsy', function () {
|
||||
testFalsyValues(function (host) {
|
||||
var test = function () {
|
||||
return new EventHubClient({ host: host });
|
||||
};
|
||||
test.should.throw(ArgumentError, 'Argument config is missing property host');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fromConnectionString', function () {
|
||||
it('throws when there\'s no connection string', function () {
|
||||
testFalsyValues(function (value) {
|
||||
|
@ -34,12 +45,12 @@ describe('EventHubClient', function () {
|
|||
});
|
||||
|
||||
it('creates an EventHubClient from a connection string', function () {
|
||||
var client = EventHubClient.fromConnectionString('EntityPath=abc');
|
||||
var client = EventHubClient.fromConnectionString('Endpoint=sb://abc;EntityPath=abc');
|
||||
client.should.be.an.instanceof(EventHubClient);
|
||||
});
|
||||
|
||||
it('creates an EventHubClient from a connection string and an Event Hub path', function () {
|
||||
var client = EventHubClient.fromConnectionString('abc', 'path');
|
||||
var client = EventHubClient.fromConnectionString('Endpoint=sb://abc', 'path');
|
||||
client.should.be.an.instanceof(EventHubClient);
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче