Raise an exception instead of attempting to write to an empty topic name

This commit is contained in:
R. Tyler Croy 2014-08-30 13:21:33 -07:00
parent 3effe046f4
commit f5e0c9384d
2 changed files with 22 additions and 11 deletions

View File

@ -487,8 +487,10 @@ static VALUE producer_push_single(VALUE self, VALUE message) {
Data_Get_Struct(self, HermannInstanceConfig, producerConfig);
if (producerConfig->topic==NULL) {
fprintf(stderr, "Topic is null!");
if ((NULL == producerConfig->topic) ||
(0 == strlen(producerConfig->topic))) {
fprintf(stderr, "Topic is null!\n");
rb_raise(rb_eRuntimeError, "Topic cannot be empty");
return self;
}

View File

@ -7,17 +7,26 @@ describe Hermann::Producer do
let(:topic) { 'rspec' }
let(:brokers) { 'localhost:1337' }
context 'with a bad broker configuration' do
let(:brokers) { '' }
it 'should raise an exception' do
expect {
producer.push('anything')
}.to raise_error(RuntimeError)
end
end
describe '#push' do
context 'error conditions' do
shared_examples 'an error condition' do
it 'should raise an exception' do
expect { producer.push('rspec') }.to raise_error(RuntimeError)
end
end
context 'with a bad broker configuration' do
let(:brokers) { '' }
it_behaves_like 'an error condition'
end
context 'with a bad topic' do
let(:topic) { '' }
it_behaves_like 'an error condition'
end
end
subject(:result) { producer.push(value) }
context 'with a single value' do