5 use Test::More tests => 14;
6 use Collectd::Unixsock;
7 use Collectd::MockDaemon;
9 my $path = mockd_start();
12 sub filter_time { return map { delete $_->{time}; $_ } @_ }
15 my ($s, $attr, $results) = @_;
16 my ($nresults, $resultdata) = @$results;
17 my $r = $s->getval(%{Collectd::Unixsock::_parse_identifier($attr)});
18 is(ref $r, 'HASH', "Got a result for $attr");
19 is(scalar keys %$r, $nresults, "$nresults result result for $attr");
20 is_deeply($r, $resultdata, "Data or $attr matches");
23 my $s = Collectd::Unixsock->new($path);
24 isnt($s, undef, "Collectd::Unixsock object created");
27 'w83df6600/vmem/vmpage_number-vmscan_write' => [ 1, { value => 0 } ],
28 'a1d8f6310/load/load' => [ 3, { longterm => '0.07', shortterm => 0, midterm => '0.06' } ],
29 'w83df6600/disk-sda/disk_octets' => [ 2, { read => 0, write => 0 } ],
32 test_query($s, $_, $queries{$_}) for sort keys %queries;
34 my @values = $s->listval;
35 is(scalar @values, 4984, "Correct number of results from LISTVAL");
36 delete $values[1234]{time}; # won't be constant
37 is_deeply($values[1234], {
38 type_instance => 'nice',
39 plugin_instance => 21,
43 }, "Correct data returned for select element");
46 is_deeply([ filter_time $s->listval_filter() ] , [ filter_time $s->listval ], "listval_filter() w/o filter equivalent to listval()");
48 [ filter_time $s->listval_filter(host => 'a1d8f6310', plugin => 'disk', plugin_instance => 'vda6') ],
50 { 'plugin_instance' => 'vda6', 'type' => 'disk_merged', 'plugin' => 'disk', 'host' => 'a1d8f6310' },
51 { 'host' => 'a1d8f6310', 'plugin' => 'disk', 'plugin_instance' => 'vda6', 'type' => 'disk_octets' },
52 { 'type' => 'disk_ops', 'plugin_instance' => 'vda6', 'plugin' => 'disk', 'host' => 'a1d8f6310' },
53 { 'plugin' => 'disk', 'host' => 'a1d8f6310', 'type' => 'disk_time', 'plugin_instance' => 'vda6' }
55 "Correct result from listval_filter on <host>, <plugin> and <plugin_instance>"
58 # TODO more test for putval() and the like