]>
git.proxmox.com Git - pve-network.git/blob - test/run_test_dns.pl
13 use PVE
::Network
::SDN
;
14 use PVE
::Network
::SDN
::Zones
;
15 use PVE
::Network
::SDN
::Controllers
;
18 use Data
::Dumper
qw(Dumper);
19 $Data::Dumper
::Sortkeys
= 1;
23 # Read structure back in again
24 open my $in, '<', $file or die $!;
27 local $/; # slurp mode
28 $sdn_config = eval <$in>;
36 my @plugins = read_dir
( './dns/', prefix
=> 1 ) ;
38 foreach my $path (@plugins) {
40 my (undef, $dnsid) = split(/\//, $path);
41 my $sdn_config = read_sdn_config
("$path/sdn_config");
45 $pve_sdn_dns = Test
::MockModule-
>new('PVE::Network::SDN::Dns');
48 my $dns_config = read_sdn_config
("$path/dns_config");
53 my $sdn_module = Test
::MockModule-
>new("PVE::Network::SDN");
59 my ($method, $url, $headers, $data) = @_;
64 my $encoded_data = $js->encode($data) if $data;
65 my $req = HTTP
::Request-
>new($method,$url, $headers, $encoded_data);
72 my $dns_cfg = PVE
::Network
::SDN
::Dns
::config
();
73 my $plugin_config = $dns_cfg->{ids
}->{$dnsid};
74 my $plugin = PVE
::Network
::SDN
::Dns
::Plugin-
>lookup($plugin_config->{type
});
77 my @ips = ("10.0.0.1", "2001:4860:4860::8888");
78 my $zone = "domain.com";
79 my $hostname = "myhostname";
81 foreach my $ip (@ips) {
83 my $ipversion = Net
::IP
::ip_is_ipv6
($ip) ?
"ipv6" : "ipv4";
84 my $type = Net
::IP
::ip_is_ipv6
($ip) ?
"AAAA" : "A";
85 my $ip2 = $type eq 'AAAA' ?
'2001:4860:4860::8844' : '127.0.0.1';
86 my $fqdn = $hostname.".".$zone.".";
88 my $sdn_dns_plugin = Test
::MockModule-
>new($plugin);
89 $sdn_dns_plugin->mock(
91 get_zone_content
=> sub {
94 get_zone_rrset
=> sub {
100 my $test = "add_a_record";
101 my $expected = Dumper read_sdn_config
("$path/expected.$test.$ipversion");
102 my $name = "$dnsid $test";
104 $plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1);
107 is ($@, $expected, $name);
113 $test = "add_ptr_record";
114 $expected = Dumper read_sdn_config
("$path/expected.$test.$ipversion");
115 $name = "$dnsid $test";
117 $plugin->add_ptr_record($plugin_config, $zone, $hostname, $ip, 1);
120 is ($@, $expected, $name);
127 $test = "del_ptr_record";
128 $expected = Dumper read_sdn_config
("$path/expected.$test.$ipversion");
129 $name = "$dnsid $test";
131 $plugin->del_ptr_record($plugin_config, $zone, $ip, 1);
134 is ($@, $expected, $name);
142 $sdn_dns_plugin->mock(
144 get_zone_content
=> sub {
147 get_zone_rrset
=> sub {
149 my $type = Net
::IP
::ip_is_ipv6
($ip) ?
"AAAA" : "A";
150 my $fqdn = $hostname.".".$zone.".";
151 my $record = { content
=> $ip,
152 disabled
=> JSON
::false
,
157 my $rrset = { name
=> $fqdn,
160 records
=> [ $record ] };
165 $test = "del_a_record";
166 $expected = Dumper read_sdn_config
("$path/expected.$test.$ipversion");
167 $name = "$dnsid $test";
169 $plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1);
172 is ($@, $expected, $name);
177 ## del_a_multiple_record
179 $sdn_dns_plugin->mock(
181 get_zone_content
=> sub {
184 get_zone_rrset
=> sub {
186 my $record = { content
=> $ip,
187 disabled
=> JSON
::false
,
192 my $record2 = { content
=> $ip2,
193 disabled
=> JSON
::false
,
198 my $rrset = { name
=> $fqdn,
201 records
=> [ $record, $record2 ] };
206 $test = "del_a_multiple_record";
207 $expected = Dumper read_sdn_config
("$path/expected.$test.$ipversion");
208 $name = "$dnsid $test";
210 $plugin->del_a_record($plugin_config, $zone, $hostname, $ip, 1);
213 is ($@, $expected, $name);
218 ## add_a_multiple_record
220 $sdn_dns_plugin->mock(
222 get_zone_content
=> sub {
225 get_zone_rrset
=> sub {
227 my $record2 = { content
=> $ip2,
228 disabled
=> JSON
::false
,
233 my $rrset = { name
=> $fqdn,
236 records
=> [ $record2 ] };
241 $test = "add_a_multiple_record";
242 $expected = Dumper read_sdn_config
("$path/expected.$test.$ipversion");
243 $name = "$dnsid $test";
245 $plugin->add_a_record($plugin_config, $zone, $hostname, $ip, 1);
248 is ($@, $expected, $name);
255 my $test = "verify_zone";
256 my $expected = Dumper read_sdn_config
("$path/expected.$test");
257 my $name = "$dnsid $test";
259 $plugin->verify_zone($plugin_config, $zone, 1);
262 is ($@, $expected, $name);