Skip to content

Commit 627fdae

Browse files
committed
Tests: pebble version and feature checks.
1 parent f4c2f07 commit 627fdae

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

t/acme_renewal.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ my $acme = Test::Nginx::ACME->new($t, port(9000), port(9001),
9999
dns_port => $dp,
100100
nosleep => 1,
101101
validity => 30,
102-
);
102+
)->has(qw/validity/);
103103

104104
$t->run_daemon(\&Test::Nginx::DNS::dns_test_daemon, $t, $dp, \@dc);
105105
$t->waitforfile($t->testdir . '/' . $dp);

t/lib/Test/Nginx/ACME.pm

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ use base qw/ Exporter /;
1616
our @EXPORT_OK = qw/ acme_test_daemon /;
1717

1818
use File::Spec;
19+
use Test::More qw//;
20+
1921
use Test::Nginx qw//;
2022

2123
our $PEBBLE = $ENV{TEST_NGINX_PEBBLE_BINARY} // 'pebble';
2224

25+
my %features = (
26+
'eab' => '2.5.2', # broken in 2.5.0
27+
'profile' => '2.7.0',
28+
'validity' => '2.4.0',
29+
);
30+
2331
sub new {
2432
my $self = {};
2533
bless $self, shift @_;
@@ -92,8 +100,59 @@ sub wait_certificate {
92100
}
93101
}
94102

103+
sub has {
104+
my ($self, @requested) = @_;
105+
106+
foreach my $feature (@requested) {
107+
Test::More::plan(skip_all => "no $feature support in pebble")
108+
unless $self->has_feature($feature);
109+
}
110+
111+
return $self;
112+
}
113+
114+
sub has_feature {
115+
my ($self, $feature) = @_;
116+
my $ver;
117+
118+
if (defined $features{$feature}) {
119+
$ver = $features{$feature};
120+
} elsif ($feature =~ /^pebble:([\d.]+)$/) {
121+
$ver = $1;
122+
} else {
123+
return 0;
124+
}
125+
126+
$self->{_version} //= _pebble_version();
127+
return 0 unless $self->{_version};
128+
129+
my @v = split(/\./, $self->{_version});
130+
my ($n, $v);
131+
132+
for my $n (split(/\./, $ver)) {
133+
$v = shift @v || 0;
134+
return 0 if $n > $v;
135+
return 1 if $v > $n;
136+
}
137+
138+
return 1;
139+
}
140+
95141
###############################################################################
96142

143+
sub _pebble_version {
144+
my $ver = `$PEBBLE -version 2>&1`;
145+
146+
if ($ver =~ /version: v?([\d.]+)/) {
147+
Test::Nginx::log_core('|| ACME: pebble version', $1);
148+
return $1;
149+
} elsif (defined $ver) {
150+
# The binary is available, but does not have the version info.
151+
Test::Nginx::log_core('|| ACME: pebble version unknown');
152+
return '0';
153+
}
154+
}
155+
97156
sub _get_body {
98157
my ($port, $uri) = @_;
99158

0 commit comments

Comments
 (0)