-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(util) move skip_openresty to Util.pm
- Loading branch information
1 parent
a799200
commit e6980c2
Showing
2 changed files
with
51 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package t::Util; | ||
|
||
sub get_openresty_canon_version (@) { | ||
sprintf "%d.%03d%03d%03d", $_[0], $_[1], $_[2], $_[3]; | ||
} | ||
|
||
sub get_openresty_version () { | ||
my $NginxBinary = $ENV{TEST_NGINX_BINARY} || 'nginx'; | ||
my $out = `$NginxBinary -V 2>&1`; | ||
|
||
if (!defined $out || $? != 0) { | ||
bail_out("Failed to get the version of the OpenResty in PATH"); | ||
die; | ||
} | ||
if ($out =~ m{openresty[^/]*/(\d+)\.(\d+)\.(\d+)\.(\d+)}s) { | ||
return get_openresty_canon_version($1, $2, $3, $4); | ||
} | ||
if ($out =~ m{nginx[^/]*/(\d+)\.(\d+)\.(\d+)}s) { | ||
return; | ||
} | ||
|
||
bail_out("Failed to parse the output of \"nginx -V\": $out\n"); | ||
die; | ||
} | ||
|
||
sub skip_openresty { | ||
my ($op, $ver) = @_; | ||
my $OpenrestyVersion = get_openresty_version(); | ||
|
||
if ($ver =~ m{(\d+)\.(\d+)\.(\d+)\.(\d+)}s) { | ||
$ver = get_openresty_canon_version($1, $2, $3, $4); | ||
} else { | ||
bail_out("Invalid skip_openresty() arg: $ver"); | ||
die; | ||
} | ||
|
||
if (defined $OpenrestyVersion and eval "$OpenrestyVersion $op $ver") { | ||
return 1; | ||
} | ||
|
||
return; | ||
} | ||
|
||
our @EXPORT = qw( | ||
skip_openresty | ||
); | ||
|
||
1; |