From 3b10e376075a8155c17f0589e4413f8783db7b3d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 10 Jan 2025 19:19:34 -0500 Subject: [PATCH] tests: dnsexit2: Add test for host outside of zone --- t/protocol_dnsexit2.pl | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/t/protocol_dnsexit2.pl b/t/protocol_dnsexit2.pl index 85ea6c9..57aa24e 100644 --- a/t/protocol_dnsexit2.pl +++ b/t/protocol_dnsexit2.pl @@ -3,6 +3,7 @@ BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } } BEGIN { eval { require JSON::PP; 1; } or plan(skip_all => $@); JSON::PP->import(); } BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); } use ddclient::t::HTTPD; +use ddclient::t::Logger; httpd_required(); @@ -180,6 +181,16 @@ my @test_cases = ( }, ], }, + { + desc => 'host outside of zone', + cfg => { + 'host.example' => { + wantipv4 => '192.0.2.1', + zone => 'example.com', + }, + }, + want_fatal => qr{hostname does not end with the zone: example.com}, + }, ); for my $tc (@test_cases) { @@ -195,7 +206,13 @@ for my $tc (@test_cases) { %{$tc->{cfg}{$h}}, }; } - ddclient::nic_dnsexit2_update(undef, @hosts); + my $l = ddclient::t::Logger->new($ddclient::_l, qr/^FATAL$/); + my $err = do { + local $ddclient::_l = $l; + local $@; + (eval { ddclient::nic_dnsexit2_update(undef, @hosts); 1; }) + ? undef : ($@ // 'unknown error'); + }; my @requests = httpd()->reset(); my @got; for (my $i = 0; $i < @requests; $i++) { @@ -212,8 +229,19 @@ for my $tc (@test_cases) { }); } @got = sort_reqs(@got); - my @want = sort_reqs(@{$tc->{want}}); + my @want = sort_reqs(@{$tc->{want} // []}); is_deeply(\@got, \@want, 'request objects match'); + subtest('expected (or lack of) error' => sub { + if (is(defined($err), defined($tc->{want_fatal}), 'error existence') && defined($err)) { + my @got = @{$l->{logs}}; + if (is(scalar(@got), 2, 'logged two events')) { + is($got[0]->{label}, 'FATAL', 'first logged event is a FATAL message'); + like($got[0]->{msg}, $tc->{want_fatal}, 'first logged event message matches'); + is($got[1], 'aborted', 'second logged event is an "aborted" event'); + isa_ok($err, qw(ddclient::t::LoggerAbort)); + } + } + }); }); }