changeset 1811:520fb74cce4c

Tests: improved njs version check to account multi digit versions.
author Dmitry Volyntsev <xeioex@nginx.com>
date Fri, 02 Dec 2022 17:46:22 -0800
parents 7cf848422b28
children f98884ad7700
files js.t js_args.t js_async.t js_fetch.t js_fetch_https.t js_headers.t js_internal_redirect.t stream_js.t stream_js_fetch.t stream_js_fetch_https.t stream_js_fetch_init.t stream_js_send.t
diffstat 12 files changed, 240 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/js.t
+++ b/js.t
@@ -301,8 +301,7 @@ like(http_get('/global'), qr/global=njs/
 like(http_get('/log'), qr/200 OK/, 'r.log');
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.7';
+local $TODO = 'not yet' unless has_version('0.7.7');
 
 like(http_get('/internal'), qr/parent: false sub: true/, 'r.internal');
 
@@ -324,6 +323,25 @@ ok(index($t->read_file('error.log'), 'at
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub http_get_hdr {
 	my ($url, %extra) = @_;
 	return http(<<EOF, %extra);
--- a/js_args.t
+++ b/js_args.t
@@ -116,9 +116,7 @@ sub get_json {
 
 ###############################################################################
 
-TODO: {
-local $TODO = 'not yet'
-    unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.6';
+local $TODO = 'not yet' unless has_version('0.7.6');
 
 like(http_get('/iter?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/,
 	'r.args iteration');
@@ -146,6 +144,24 @@ is(get_json('/object?a=%62%63&b=%63%64')
 is(get_json('/object?a=%6&b=%&c=%%&d=%zz'),
 	'{"a":"%6","b":"%","c":"%%","d":"%zz"}',
 	'values percent-encoded broken object');
+
+###############################################################################
+
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
 }
 
 ###############################################################################
--- a/js_async.t
+++ b/js_async.t
@@ -211,8 +211,7 @@ like(http_get('/shared_ctx?a=xxx'), qr/H
 like(http_get('/limit_rate'), qr/A{50}/, 'limit_rate');
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0';
+local $TODO = 'not yet' unless has_version('0.7.0');
 
 like(http_get('/async_content'), qr/retval: AB/, 'async content');
 like(http_get('/set_rv_var'), qr/retval: 30/, 'set return value variable');
@@ -229,3 +228,22 @@ ok(index($t->read_file('error.log'), 'as
    'async op in var handler');
 
 ###############################################################################
+
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
--- a/js_fetch.t
+++ b/js_fetch.t
@@ -453,7 +453,7 @@ like(http_get('/chain'), qr/200 OK.*SUCC
 
 TODO: {
 todo_skip 'leaves coredump', 1 unless $ENV{TEST_NGINX_UNSAFE}
-	or http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.4';
+	or has_version('0.7.4');
 
 like(http_get('/header_iter?loc=duplicate_header_large'),
 	qr/\['A:a','B:a','C:a','D:a','E:a','F:a','G:a','H:a','Foo:a,b']$/s,
@@ -462,8 +462,7 @@ like(http_get('/header_iter?loc=duplicat
 }
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.7';
+local $TODO = 'not yet' unless has_version('0.7.7');
 
 like(http_get('/body_special?loc=no_content_length'),
 	qr/200 OK.*CONTENT-BODY$/s, 'fetch body without content-length');
@@ -473,8 +472,7 @@ like(http_get('/body_special?loc=no_cont
 }
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.8';
+local $TODO = 'not yet' unless has_version('0.7.8');
 
 like(http_get('/body_special?loc=head&method=HEAD'),
 	qr/200 OK.*<empty>$/s, 'fetch head method');
@@ -485,6 +483,25 @@ like(http_get('/body_special?loc=length&
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub recode {
 	my $json;
 	eval { $json = JSON::PP::decode_json(shift) };
--- a/js_fetch_https.t
+++ b/js_fetch_https.t
@@ -190,8 +190,7 @@ foreach my $name ('default.example.com',
 
 ###############################################################################
 
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0';
+local $TODO = 'not yet' unless has_version('0.7.0');
 
 like(http_get('/https?domain=default.example.com&verify=false'),
 	qr/You are at default.example.com.$/s, 'fetch https');
@@ -210,6 +209,25 @@ like(http_get('/https.myca.short?domain=
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub reply_handler {
 	my ($recv_data, $port, %extra) = @_;
 
--- a/js_headers.t
+++ b/js_headers.t
@@ -531,8 +531,7 @@ like(http(
 ), qr/a,b,c/, 'r.headersOut sorted keys');
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.6';
+local $TODO = 'not yet' unless has_version('0.7.6');
 
 like(http_get('/hdr_out_special_set'), qr/CE: abc/,
 	'r.headerOut special set');
@@ -548,3 +547,22 @@ like(http_get('/copy_subrequest_hdrs'),
 }
 
 ###############################################################################
+
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
--- a/js_internal_redirect.t
+++ b/js_internal_redirect.t
@@ -100,8 +100,7 @@ like(http_get('/test?a=A'), qr/redirectA
 like(http_get('/test?dest=named'), qr/named/s, 'redirect to named location');
 
 TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.4';
+local $TODO = 'not yet' unless has_version('0.7.4');
 
 like(http_get('/test?unsafe=1'), qr/500 Internal Server/s,
 	'unsafe redirect');
@@ -110,3 +109,22 @@ like(http_get('/test?quoted=1'), qr/200 
 }
 
 ###############################################################################
+
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
--- a/stream_js.t
+++ b/stream_js.t
@@ -416,8 +416,7 @@ stream('127.0.0.1:' . port(8098))->io('x
 stream('127.0.0.1:' . port(8099))->io('x');
 
 TODO: {
-local $TODO = 'not yet'
-	unless get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0';
+local $TODO = 'not yet' unless has_version('0.7.0');
 
 is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'asyncf');
 
@@ -438,6 +437,25 @@ like($t->read_file('status.log'), qr/$p[
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub stream_daemon {
 	my $server = IO::Socket::INET->new(
 		Proto => 'tcp',
--- a/stream_js_fetch.t
+++ b/stream_js_fetch.t
@@ -188,7 +188,7 @@ is(stream('127.0.0.1:' . port(8081))->io
 
 TODO: {
 todo_skip 'leaves coredump', 3 unless $ENV{TEST_NGINX_UNSAFE}
-	or http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.7';
+	or has_version('0.7.7');
 
 my $s = stream('127.0.0.1:' . port(8082));
 is($s->io("\xAB\xCDQZ##", read => 1), '##', 'filter validated');
@@ -204,6 +204,25 @@ is(stream('127.0.0.1:' . port(8084))->io
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub stream_daemon {
 	my (@ports) = @_;
 	my (@socks, @clients);
--- a/stream_js_fetch_https.t
+++ b/stream_js_fetch_https.t
@@ -270,8 +270,7 @@ foreach my $name ('default.example.com',
 
 ###############################################################################
 
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0';
+local $TODO = 'not yet' unless has_version('0.7.0');
 
 like(stream("127.0.0.1:$p2")->io('GOdefault.example.com'),
 	qr/connect failed/s, 'stream non trusted CA');
@@ -289,6 +288,25 @@ is(https_get('default.example.com', port
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub get_ssl_socket {
 	my ($host, $port) = @_;
 	my $s;
--- a/stream_js_fetch_init.t
+++ b/stream_js_fetch_init.t
@@ -95,13 +95,31 @@ EOF
 
 ###############################################################################
 
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.9';
+local $TODO = 'not yet' unless has_version('0.7.9');
 
 is(stream('127.0.0.1:' . port(8081))->io('ABC'), 'ABC', 'access fetch ok');
 
 ###############################################################################
 
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
+
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
+
+###############################################################################
+
 sub stream_daemon {
 	my $server = IO::Socket::INET->new(
 		Proto => 'tcp',
--- a/stream_js_send.t
+++ b/stream_js_send.t
@@ -128,18 +128,31 @@ EOF
 
 ###############################################################################
 
-TODO: {
-local $TODO = 'not yet'
-	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.8';
-
 is(stream('127.0.0.1:' . port(8081))->io('abc'), 'ABC',
 	'async filter');;
 is(stream('127.0.0.1:' . port(8082))->io('abc'), 'xxxABC',
 	'async filter direct');
 
-}
+$t->stop();
+
+###############################################################################
+
+sub has_version {
+	my $need = shift;
+
+	http_get('/njs') =~ /^([.0-9]+)$/m;
 
-$t->stop();
+	my @v = split(/\./, $1);
+	my ($n, $v);
+
+	for $n (split(/\./, $need)) {
+		$v = shift @v || 0;
+		return 0 if $n > $v;
+		return 1 if $v > $n;
+	}
+
+	return 1;
+}
 
 ###############################################################################