Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
haio committed Nov 14, 2013
1 parent 89ecaf9 commit 194b55a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Producer.prototype.createTopics = function (topics, async, cb) {
return;
}
topics = typeof topic === 'string' ? [topics] : topics;
if (typeof async === 'function' || typeof async === 'undefined') {
if (typeof async === 'function' && typeof cb === 'undefined') {
cb = async;
async = true;
}
Expand Down
21 changes: 16 additions & 5 deletions test/test.producer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict';

var libPath = process.env['kafka-cov'] ? '../lib-cov/' : '../lib/',
Producer = require(libPath + 'producer'),
Client = require(libPath + 'client');
var Producer = require('../lib/producer'),
Client = require('../lib/client');

var client, producer;

// Helper method
function randomId () {
return Math.floor(Math.random() * 10000)
}

before(function (done) {
client = new Client();
producer = new Producer(client);
Expand Down Expand Up @@ -35,14 +39,21 @@ describe('Producer', function () {

describe('#createTopics', function () {
it('should return All requests sent when async is true', function (done) {
producer.createTopics(['_exist_topic_4_test'], function (err, data) {
producer.createTopics(['_exist_topic_'+ randomId() +'_test'], true, function (err, data) {
data.should.equal('All requests sent');
done(err);
});
});

it('async should be true if not present', function (done) {
producer.createTopics(['_exist_topic_'+ randomId() +'_test'], function (err, data) {
data.should.equal('All requests sent');
done(err);
});
});

it('should return All created when async is false', function (done) {
producer.createTopics(['_exist_topic_4_test'], false, function (err, data) {
producer.createTopics(['_exist_topic_'+ randomId() +'_test'], false, function (err, data) {
data.should.equal('All created');
done(err);
});
Expand Down

0 comments on commit 194b55a

Please sign in to comment.