1#!/usr/bin/perl -w
2
3use Net::DRI::Data::Hosts;
4
5use Test::More tests => 25;
6
7my $d=Net::DRI::Data::Hosts->new();
8isa_ok($d,'Net::DRI::Data::Hosts');
9
10$d=Net::DRI::Data::Hosts->new('ns.example.foo',['1.2.3.4','1.2.3.5']);
11$d->name('test1');
12$d->loid(12345);
13isa_ok($d,'Net::DRI::Data::Hosts');
14is($d->count(),1,'count()');
15my @c;
16@c=$d->get_details(1);
17is_deeply($c[1],['1.2.3.4','1.2.3.5'],'get_details(integer) ip address');
18is($d->name(),'test1','name()');
19is($d->loid(),12345,'loid()');
20
21@c=$d->get_details('ns.example.foo');
22is_deeply($c[1],['1.2.3.4','1.2.3.5'],'get_details(name) ip address');
23$d->add('ns.example.foo',['1.2.3.5']);
24@c=$d->get_details('ns.example.foo');
25is_deeply($c[1],['1.2.3.4','1.2.3.5'],'get_details(name) ip address add 1');
26$d->add('ns.example.foo',['1.2.3.6']);
27@c=$d->get_details('ns.example.foo');
28is_deeply($c[1],['1.2.3.4','1.2.3.5','1.2.3.6'],'get_details(name) ip address add 2');
29$d->add('ns.example.foo',[],['2001:0:0:0:8:800:200C:417A']);
30@c=$d->get_details('ns.example.foo');
31is_deeply($c[1],['1.2.3.4','1.2.3.5','1.2.3.6'],'get_details(name) ip address add 3 ip4');
32is_deeply($c[2],['2001:0:0:0:8:800:200C:417A'],'get_details(name) ip address add 3 ip6');
33
34$d=Net::DRI::Data::Hosts->new('ns.example.foo',['1.2.3.4','1.2.3.4']);
35isa_ok($d,'Net::DRI::Data::Hosts');
36@c=$d->get_details(1);
37is_deeply($c[1],['1.2.3.4'],'remove dups IP');
38is(($d->get_names(1))[0],'ns.example.foo','get_names()');
39
40my $dd=$d->add('ns2.example.foo',['1.2.10.4']);
41isa_ok($dd,'Net::DRI::Data::Hosts');
42is_deeply($d,$dd,'add() returns the object itself');
43@c=$d->get_names();
44is_deeply(\@c,['ns.example.foo','ns2.example.foo'],'get_names() after add');
45@c=$d->get_names(2);
46is_deeply(\@c,['ns.example.foo','ns2.example.foo'],'get_names(2) after add');
47@c=$d->get_names(1);
48is_deeply(\@c,['ns.example.foo'],'get_names(1) after add');
49
50$d->set(['ns.example.foo',['1.2.3.4','1.2.3.5']]);
51is($d->count(),1,'count() after set()');
52@c=$d->get_details(1);
53is_deeply($c[1],['1.2.3.4','1.2.3.5'],'get_details(integer) ip address after set()');
54
55$d->add('test.extra.parameters',[],[],{key1=>'v1',key2=>2});
56@c=$d->get_details(2);
57isa_ok($c[-1],'HASH');
58is_deeply($c[-1],{key1=>'v1',key2=>2},'correct retrieval of extra parameters');
59$d->add('test.extra.parameters',[],[],{key2=>22,key3=>'whatever'});
60@c=$d->get_details(2);
61is_deeply($c[-1],{key1=>'v1',key2=>22,key3=>'whatever'},'correct retrieval of extra parameters after merge');
62
63TODO: {
64        local $TODO='tests on add() with other params, new_set(), is_empty()';
65        ok(0);
66}
67
68exit 0;
69