Skip to content

Commit

Permalink
tests(util) move skip_openresty to Util.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Jun 5, 2018
1 parent a799200 commit e6980c2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
45 changes: 3 additions & 42 deletions t/02-get.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,8 @@

use Test::Nginx::Socket::Lua;
use Cwd qw(cwd);

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;
}
use lib '.';
use t::Util;

no_long_string();

Expand Down Expand Up @@ -1324,7 +1285,7 @@ hit level from shm: 2


=== TEST 28: get() returns hit level for boolean false hits
--- skip_eval: 3: main::skip_openresty('<', '1.11.2.3')
--- skip_eval: 3: t::Util::skip_openresty('<', '1.11.2.3')
--- http_config eval: $::HttpConfig
--- config
location = /t {
Expand Down
48 changes: 48 additions & 0 deletions t/Util.pm
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;

0 comments on commit e6980c2

Please sign in to comment.