Skip to content

Commit

Permalink
Catch stderr output from bulk_buf_add methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lorf committed Mar 21, 2014
1 parent 16309df commit b416312
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions t/bulk_buf.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use warnings;
use strict;
use Test::More;
use Test::Output qw(stderr_from);

my $test_counter = 0;

Expand All @@ -12,19 +13,23 @@ $test_counter++;

my $host = 'sender';
my $zs = Zabbix::Sender->new( server => 'server', hostname => $host );
# Valid usage of bulk_buf_add, these should accumulate in the buffer
$zs->bulk_buf_add('k11', 'v11', 1234567811, 'k12', 'v12');
$zs->bulk_buf_add(['k21', 'v21', undef], ['k22', 'v22', 1234567822]);
$zs->bulk_buf_add(
'host31', [ ['k31', 'v31', '1234567831'], ['k32', 'v32', ''] ],
'host32', [ ['k33', 'v33'], ['k34', 'v34', 1234567834] ]);
# Invalid usage, these shouldn't get to the buffer
$zs->bulk_buf_add('k');
$zs->bulk_buf_add({'k' => 'v61'});
$zs->bulk_buf_add(['k']);
$zs->bulk_buf_add(['k', 'v', 1, 'dummy']);
$zs->bulk_buf_add('h', ['k', 'v']);
$zs->bulk_buf_add('h', {'k' => 'v'});

# Catch output of carp call from Zabbix::Sender
my $out = stderr_from {
# Valid usage of bulk_buf_add, these should accumulate in the buffer
$zs->bulk_buf_add('k11', 'v11', 1234567811, 'k12', 'v12');
$zs->bulk_buf_add(['k21', 'v21', undef], ['k22', 'v22', 1234567822]);
$zs->bulk_buf_add(
'host31', [ ['k31', 'v31', '1234567831'], ['k32', 'v32', ''] ],
'host32', [ ['k33', 'v33'], ['k34', 'v34', 1234567834] ]);
# Invalid usage, these shouldn't get to the buffer
$zs->bulk_buf_add('k');
$zs->bulk_buf_add({'k' => 'v61'});
$zs->bulk_buf_add(['k']);
$zs->bulk_buf_add(['k', 'v', 1, 'dummy']);
$zs->bulk_buf_add('h', ['k', 'v']);
$zs->bulk_buf_add('h', {'k' => 'v'});
};

# What we should get
my $test_result = [
Expand Down

0 comments on commit b416312

Please sign in to comment.