mirror of https://github.com/reiseburo/hermann
Raise an exception instead of attempting to write to an empty topic name
This commit is contained in:
parent
3effe046f4
commit
f5e0c9384d
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue