tests: Factor out duplicate log capture code
This commit is contained in:
parent
d18b1cdb27
commit
009033d476
4 changed files with 24 additions and 36 deletions
|
@ -160,5 +160,6 @@ EXTRA_DIST += $(handwritten_tests) \
|
||||||
t/lib/ddclient/Test/Fake/HTTPD/other-ca-cert.pem \
|
t/lib/ddclient/Test/Fake/HTTPD/other-ca-cert.pem \
|
||||||
t/lib/ddclient/t.pm \
|
t/lib/ddclient/t.pm \
|
||||||
t/lib/ddclient/t/HTTPD.pm \
|
t/lib/ddclient/t/HTTPD.pm \
|
||||||
|
t/lib/ddclient/t/Logger.pm \
|
||||||
t/lib/ddclient/t/ip.pm \
|
t/lib/ddclient/t/ip.pm \
|
||||||
t/lib/ok.pm
|
t/lib/ok.pm
|
||||||
|
|
19
t/lib/ddclient/t/Logger.pm
Normal file
19
t/lib/ddclient/t/Logger.pm
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package ddclient::t::Logger;
|
||||||
|
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
||||||
|
use parent qw(-norequire ddclient::Logger);
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, $parent) = @_;
|
||||||
|
my $self = $class->SUPER::new(undef, $parent);
|
||||||
|
$self->{logs} = [];
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _log {
|
||||||
|
my ($self, $args) = @_;
|
||||||
|
push(@{$self->{logs}}, $args)
|
||||||
|
if ($args->{label} // '') =~ qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/;
|
||||||
|
return $self->SUPER::_log($args);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -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 JSON::PP; 1; } or plan(skip_all => $@); JSON::PP->import(); }
|
||||||
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
||||||
use ddclient::t::HTTPD;
|
use ddclient::t::HTTPD;
|
||||||
|
use ddclient::t::Logger;
|
||||||
|
|
||||||
httpd_required();
|
httpd_required();
|
||||||
|
|
||||||
|
@ -29,23 +30,6 @@ httpd()->run(sub {
|
||||||
return [400, $headers, ['unexpected request: ' . $req->uri()]]
|
return [400, $headers, ['unexpected request: ' . $req->uri()]]
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
|
||||||
package Logger;
|
|
||||||
use parent qw(-norequire ddclient::Logger);
|
|
||||||
sub new {
|
|
||||||
my ($class, $parent) = @_;
|
|
||||||
my $self = $class->SUPER::new(undef, $parent);
|
|
||||||
$self->{logs} = [];
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
sub _log {
|
|
||||||
my ($self, $args) = @_;
|
|
||||||
push(@{$self->{logs}}, $args)
|
|
||||||
if ($args->{label} // '') =~ qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/;
|
|
||||||
return $self->SUPER::_log($args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my $hostname = httpd()->endpoint();
|
my $hostname = httpd()->endpoint();
|
||||||
my @test_cases = (
|
my @test_cases = (
|
||||||
{
|
{
|
||||||
|
@ -149,7 +133,7 @@ for my $tc (@test_cases) {
|
||||||
diag('==============================================================================');
|
diag('==============================================================================');
|
||||||
local $ddclient::globals{debug} = 1;
|
local $ddclient::globals{debug} = 1;
|
||||||
local $ddclient::globals{verbose} = 1;
|
local $ddclient::globals{verbose} = 1;
|
||||||
my $l = Logger->new($ddclient::_l);
|
my $l = ddclient::t::Logger->new($ddclient::_l);
|
||||||
local %ddclient::config = %{$tc->{cfg}};
|
local %ddclient::config = %{$tc->{cfg}};
|
||||||
local %ddclient::recap;
|
local %ddclient::recap;
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ BEGIN { SKIP: { eval { require Test::Warnings; 1; } or skip($@, 1); } }
|
||||||
use MIME::Base64;
|
use MIME::Base64;
|
||||||
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
||||||
use ddclient::t::HTTPD;
|
use ddclient::t::HTTPD;
|
||||||
|
use ddclient::t::Logger;
|
||||||
|
|
||||||
httpd_required();
|
httpd_required();
|
||||||
|
|
||||||
|
@ -18,23 +19,6 @@ httpd()->run(sub {
|
||||||
return undef;
|
return undef;
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
|
||||||
package Logger;
|
|
||||||
use parent qw(-norequire ddclient::Logger);
|
|
||||||
sub new {
|
|
||||||
my ($class, $parent) = @_;
|
|
||||||
my $self = $class->SUPER::new(undef, $parent);
|
|
||||||
$self->{logs} = [];
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
sub _log {
|
|
||||||
my ($self, $args) = @_;
|
|
||||||
push(@{$self->{logs}}, $args)
|
|
||||||
if ($args->{label} // '') =~ qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/;
|
|
||||||
return $self->SUPER::_log($args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my @test_cases = (
|
my @test_cases = (
|
||||||
{
|
{
|
||||||
desc => 'IPv4, single host, good',
|
desc => 'IPv4, single host, good',
|
||||||
|
@ -246,7 +230,7 @@ for my $tc (@test_cases) {
|
||||||
diag('==============================================================================');
|
diag('==============================================================================');
|
||||||
local $ddclient::globals{debug} = 1;
|
local $ddclient::globals{debug} = 1;
|
||||||
local $ddclient::globals{verbose} = 1;
|
local $ddclient::globals{verbose} = 1;
|
||||||
my $l = Logger->new($ddclient::_l);
|
my $l = ddclient::t::Logger->new($ddclient::_l);
|
||||||
local %ddclient::config;
|
local %ddclient::config;
|
||||||
local %ddclient::recap;
|
local %ddclient::recap;
|
||||||
$ddclient::config{$_} = {
|
$ddclient::config{$_} = {
|
||||||
|
|
Loading…
Reference in a new issue