~ubuntu-branches/ubuntu/vivid/libzabbix-api-perl/vivid

« back to all changes in this revision

Viewing changes to t/hostgroups.t

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-08-11 04:26:46 UTC
  • Revision ID: package-import@ubuntu.com-20120811042646-le16xahtf2pjzxuv
Tags: upstream-0.004+git20120629
ImportĀ upstreamĀ versionĀ 0.004+git20120629

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use Test::More;
 
2
use Test::Exception;
 
3
use Data::Dumper;
 
4
 
 
5
use Zabbix::API;
 
6
 
 
7
use lib 't/lib';
 
8
use Zabbix::API::TestUtils;
 
9
 
 
10
if ($ENV{ZABBIX_SERVER}) {
 
11
 
 
12
    plan tests => 7;
 
13
 
 
14
} else {
 
15
 
 
16
    plan skip_all => 'Needs an URL in $ENV{ZABBIX_SERVER} to run tests.';
 
17
 
 
18
}
 
19
 
 
20
use_ok('Zabbix::API::HostGroup');
 
21
 
 
22
my $zabber = Zabbix::API::TestUtils::canonical_login;
 
23
 
 
24
my $hostgroups = $zabber->fetch('HostGroup', params => { search => { name => 'Zabbix servers' } });
 
25
 
 
26
is(@{$hostgroups}, 1, '... and a host group known to exist can be fetched');
 
27
 
 
28
my $zabhost = $hostgroups->[0];
 
29
 
 
30
isa_ok($zabhost, 'Zabbix::API::HostGroup',
 
31
       '... and that host group');
 
32
 
 
33
ok($zabhost->created,
 
34
   '... and it returns true to existence tests');
 
35
 
 
36
my $new_hostgroup = Zabbix::API::HostGroup->new(root => $zabber,
 
37
                                                data => { name => 'Another HostGroup' });
 
38
 
 
39
isa_ok($new_hostgroup, 'Zabbix::API::HostGroup',
 
40
       '... and a hostgroup created manually');
 
41
 
 
42
eval { $new_hostgroup->push };
 
43
 
 
44
if ($@) { diag "Caught exception: $@" };
 
45
 
 
46
ok($new_hostgroup->created,
 
47
   '... and pushing it to the server creates a new hostgroup');
 
48
 
 
49
eval { $new_hostgroup->delete };
 
50
 
 
51
if ($@) { diag "Caught exception: $@" };
 
52
 
 
53
TODO: {
 
54
 
 
55
    todo_skip 'Current version of the API does not allow even Super Admins to delete HostGroups', 1;
 
56
 
 
57
    ok(!$new_hostgroup->created,
 
58
       '... and calling its delete method removes it from the server');
 
59
 
 
60
}
 
61
 
 
62
eval { $zabber->logout };