message-hub-rest
Version:
Node.js module for connecting to the Kafka REST interface of IBM Message Hub.
97 lines (79 loc) • 2.94 kB
JavaScript
/**
* Copyright 2015 IBM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Licensed Materials - Property of IBM
* © Copyright IBM Corp. 2015
*/
;
var MessageHub = require('../../lib/messagehub');
var KafkaMock = require('../kafka-mock');
var Expect = require('expect.js');
module.exports.run = function(services, port, useMockService) {
describe('[Client] Functionality', function() {
it('Provides helper classes on module.exports', function() {
Expect(MessageHub).to.be.a('function');
});
it('Loads correctly with well-formed VCAP_SERVICES input', function() {
var instance = new MessageHub(services);
var sentApiKey;
// Retrieve the API key sent in the services object.
for(var index in services["messagehub"]) {
if(services["messagehub"][index].hasOwnProperty("label")
&& services["messagehub"][index].label == "messagehub")
{
sentApiKey = services["messagehub"][index].credentials.api_key;
}
}
Expect(instance.apiKey).not.to.be(undefined);
Expect(instance.apiKey).to.be.a('string');
Expect(instance.apiKey).to.equal(sentApiKey);
Expect(instance.url).not.to.be(undefined);
});
it('Defaults https option to true', function() {
var instance = new MessageHub(services);
var instanceWithArg = new MessageHub(services);
Expect(instance.config).not.to.be(null);
Expect(instance.config.https).not.to.be(null);
Expect(instance.config.https).to.be(true);
Expect(instanceWithArg.config).not.to.be(null);
Expect(instanceWithArg.config.https).not.to.be(null);
Expect(instanceWithArg.config.https).to.be(true);
});
it('Throws an exception if services parameter is undefined or null', function() {
try {
new MessageHub(undefined);
} catch(e) {
Expect(e).to.be.an(Error);
}
try {
new MessageHub(null);
} catch(e) {
Expect(e).to.be.an(Error);
return;
}
done(new Error('MessageHub constructor did not throw an exception.'));
});
it('Throws an exception if "messagehub" key is not defined in VCAP_SERVICES', function() {
try {
new MessageHub({ });
} catch(e) {
Expect(e).to.be.an(Error);
return;
}
done(new Error('MessageHub constructor did not throw an exception.'));
});
});
};