8
use Zabbix::API::TestUtils;
10
if ($ENV{ZABBIX_SERVER}) {
16
plan skip_all => 'Needs an URL in $ENV{ZABBIX_SERVER} to run tests.';
20
use_ok('Zabbix::API::HostGroup');
22
my $zabber = Zabbix::API::TestUtils::canonical_login;
24
my $hostgroups = $zabber->fetch('HostGroup', params => { search => { name => 'Zabbix servers' } });
26
is(@{$hostgroups}, 1, '... and a host group known to exist can be fetched');
28
my $zabhost = $hostgroups->[0];
30
isa_ok($zabhost, 'Zabbix::API::HostGroup',
31
'... and that host group');
34
'... and it returns true to existence tests');
36
my $new_hostgroup = Zabbix::API::HostGroup->new(root => $zabber,
37
data => { name => 'Another HostGroup' });
39
isa_ok($new_hostgroup, 'Zabbix::API::HostGroup',
40
'... and a hostgroup created manually');
42
eval { $new_hostgroup->push };
44
if ($@) { diag "Caught exception: $@" };
46
ok($new_hostgroup->created,
47
'... and pushing it to the server creates a new hostgroup');
49
eval { $new_hostgroup->delete };
51
if ($@) { diag "Caught exception: $@" };
55
todo_skip 'Current version of the API does not allow even Super Admins to delete HostGroups', 1;
57
ok(!$new_hostgroup->created,
58
'... and calling its delete method removes it from the server');
62
eval { $zabber->logout };