зеркало из
1
0
Форкнуть 0

Client ctor takes config object with host property

This commit is contained in:
Damon Barry 2015-11-19 11:55:43 -08:00
Родитель 0eb3035f1d
Коммит 1d32a9aa1e
3 изменённых файлов: 37 добавлений и 4 удалений

Просмотреть файл

@ -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
Просмотреть файл

@ -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);
});
});