File: 06-update-unique-push.t

package info (click to toggle)
libnet-dns-perl 1.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: perl: 18,185; makefile: 9
file content (106 lines) | stat: -rw-r--r-- 2,990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/perl
# $Id: 06-update-unique-push.t 1895 2023-01-16 13:38:08Z willem $
#

use strict;
use warnings;
use Test::More tests => 45;

use_ok('Net::DNS');


# Matching of RR name is not case sensitive
my $domain = 'example.com';
my $method = 'unique_push';
my $packet = Net::DNS::Update->new($domain);

my $rr_1 = Net::DNS::RR->new('bla.foo 100 IN TXT "text" ;lower case');
my $rr_2 = Net::DNS::RR->new('bla.Foo 100 IN Txt "text" ;mixed case');
my $rr_3 = Net::DNS::RR->new('bla.foo 100 IN TXT "mixed CASE"');
my $rr_4 = Net::DNS::RR->new('bla.foo 100 IN TXT "MIXED case"');

$packet->$method( "answer", $rr_1 );
$packet->$method( "answer", $rr_2 );
is( $packet->header->ancount, 1, "$method case sensitivity test 1" );

$packet->$method( "answer", $rr_3 );
$packet->$method( "answer", $rr_4 );
is( $packet->header->ancount, 3, "$method case sensitivity test 2" );


my %sections = (
	answer	   => 'ancount',
	authority  => 'nscount',
	additional => 'arcount',
	);

my @tests = (
	[	1,
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		],
	[	2,
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('bar.example.com 60 IN A 192.0.2.1'),
		],
	[	1,
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 90 IN A 192.0.2.1'),
		],
	[	3,
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.2'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.3'),
		],
	[	3,
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.2'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.3'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		],
	[	3,
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.2'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.1'),
		Net::DNS::RR->new('foo.example.com 60 IN A 192.0.2.4'),
		Net::DNS::RR->new('foo.example.com 60 HS A 192.0.2.4'),
		],
	[	3,						# without RDATA
		Net::DNS::RR->new('foo.example.com IN A'),
		Net::DNS::RR->new('foo.example.com ANY A'),
		Net::DNS::RR->new('foo.example.com NONE A'),
		],
	);


foreach my $test (@tests) {
	my ( $expect, @rrs ) = @$test;

	while ( my ( $section, $count_meth ) = each %sections ) {

		my $packet = Net::DNS::Update->new($domain);

		$packet->$method( $section => @rrs );

		my $count = $packet->header->$count_meth();
		is( $count, $expect, "$method  $section	=> RR, RR, ..." );

	}

	#
	# Now do it again, pushing each RR individually.
	#
	while ( my ( $section, $count_meth ) = each %sections ) {

		my $packet = Net::DNS::Update->new($domain);

		foreach my $rr (@rrs) {
			$packet->$method( $section => $rr );
		}

		my $count = $packet->header->$count_meth();
		is( $count, $expect, "$method  $section	=> RR" );
	}
}