Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[t] use one base class #458

Merged
merged 4 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions t/001-management.t
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";
use TestAPIcast 'no_plan';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is no_plan ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know. I guess it defines in what order to execute the tests. Search for plan on http://search.cpan.org/~agent/Test-Nginx/lib/Test/Nginx/Socket.pm

https://openresty.gitbooks.io/programming-openresty/content/ also have few mentions of it.


$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_MANAGEMENT_CONFIG} = "$apicast/conf.d/management.conf";

require("$pwd/t/dns.pl");

log_level('debug');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down Expand Up @@ -177,8 +167,8 @@ POST /boot
{"status":"ok","config":{"services":[{"id":42}]}}
--- error_code: 200
--- udp_listen: 1953
--- udp_reply eval
$::dns->("localhost.local", "127.0.0.1", 60)
--- udp_reply dns
[ "localhost.local", "127.0.0.1", 60 ]
--- no_error_log
[error]

Expand Down Expand Up @@ -206,8 +196,8 @@ POST /test
{"status":"ok","config":{"services":[{"id":42}]}}
--- error_code: 200
--- udp_listen: 1953
--- udp_reply eval
$::dns->("localhost.local", "127.0.0.1", 60)
--- udp_reply dns
[ "localhost.local", "127.0.0.1", 60 ]
--- no_error_log
[error]

Expand Down
17 changes: 4 additions & 13 deletions t/002-backend.t
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

our $HttpConfig = qq{
lua_package_path "$apicast/src/?.lua;;";
};
our $backendConfig = "$apicast/conf.d/backend.conf";

repeat_each(2);
run_tests();

__DATA__

=== TEST 1: backend
This is just a simple demonstration of the
echo directive provided by ngx_http_echo_module.
--- http_config eval: $::HttpConfig
--- config eval: "include $::backendConfig;"
--- config
include $TEST_NGINX_BACKEND_CONFIG;
--- request
GET /transactions/authrep.xml
--- response_body
Expand Down
21 changes: 4 additions & 17 deletions t/003-apicast.t
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

require("$pwd/t/dns.pl");

log_level('debug');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down Expand Up @@ -634,8 +621,8 @@ GET /t?user_key=val
all ok
--- error_code: 200
--- udp_listen: 1953
--- udp_reply eval
$::dns->("localhost.example.com", "127.0.0.1", 3600)
--- udp_reply dns
[ "localhost.example.com", "127.0.0.1", 3600 ]
--- no_error_log
[error]

Expand Down
13 changes: 2 additions & 11 deletions t/004-apicast-path-routing.t
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";
$ENV{APICAST_PATH_ROUTING_ENABLED} = '1';

log_level('debug');
repeat_each(1); # Can't be 2 as the second run would hit the cache
no_root_location();
run_tests();

__DATA__
Expand Down
13 changes: 2 additions & 11 deletions t/004-custom-config.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

log_level('debug');
repeat_each(2);
run_tests();

__DATA__
Expand Down
18 changes: 5 additions & 13 deletions t/005-apicast-oauth.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";
use lib 't';
use TestAPIcast 'no_plan';

$ENV{TEST_NGINX_REDIS_HOST} ||= $ENV{REDIS_HOST} || "127.0.0.1";
$ENV{TEST_NGINX_RESOLVER} ||= `grep nameserver /etc/resolv.conf | awk '{print \$2}' | head -1 | tr '\n' ' '`;
$ENV{BACKEND_ENDPOINT_OVERRIDE} ||= "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient/backend";

env_to_nginx('BACKEND_ENDPOINT_OVERRIDE');

log_level('debug');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down
15 changes: 2 additions & 13 deletions t/006-apicast-subset-of-services.t
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

log_level('debug');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down
22 changes: 6 additions & 16 deletions t/007-apicast-upstream-balancer.t
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";
$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";

require("$pwd/t/dns.pl");

log_level('debug');
repeat_each(2);
no_root_location();
run_tests();


__DATA__

=== TEST 1: resolver
Expand Down Expand Up @@ -42,8 +32,8 @@ location /t {
}
}
--- udp_listen: 1953
--- udp_reply eval
$::dns->("localhost", "127.0.0.1")
--- udp_reply dns
[ "localhost", "127.0.0.1" ]
--- request
GET /t
--- response_body
Expand Down Expand Up @@ -135,8 +125,8 @@ location /t {
proxy_pass http://upstream/api;
}
--- udp_listen: 1953
--- udp_reply eval
$::dns->("localhost", "127.0.0.1")
--- udp_reply dns
[ "localhost", "127.0.0.1" ]
--- request
GET /t
--- response_body
Expand Down
19 changes: 3 additions & 16 deletions t/008-apicast-request-logs.t
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use Sys::Hostname;

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

our $host = hostname;
$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

log_level('debug');
repeat_each(2);
no_root_location();
use lib 't';
use TestAPIcast 'no_plan';

run_tests();

__DATA__
Expand Down
14 changes: 2 additions & 12 deletions t/009-apicast-caching.t
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

log_level('debug');
repeat_each(1); # Can't be two as the second call would hit the cache
no_root_location();
run_tests();

__DATA__
Expand Down
15 changes: 2 additions & 13 deletions t/010-apicast-mapping-rules.t
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";

log_level('debug');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down
13 changes: 3 additions & 10 deletions t/011-configuration-loading-boot-without-config.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use Test::Nginx::Socket 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_HTTP_CONFIG} = "$apicast/http.d/init.conf";
$ENV{TEST_NGINX_APICAST_PATH} = $apicast;
$ENV{TEST_NGINX_HTTP_CONFIG} = "$TestAPIcast::path/http.d/init.conf";
$ENV{APICAST_CONFIGURATION_LOADER} = 'boot';

env_to_nginx(
Expand All @@ -16,8 +11,6 @@ env_to_nginx(
);

log_level('emerg');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down
13 changes: 3 additions & 10 deletions t/012-configuration-loading-boot-with-config.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use Test::Nginx::Socket 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_HTTP_CONFIG} = "$apicast/http.d/init.conf";
$ENV{TEST_NGINX_APICAST_PATH} = $apicast;
$ENV{TEST_NGINX_HTTP_CONFIG} = "$TestAPIcast::path/http.d/init.conf";
$ENV{APICAST_CONFIGURATION_LOADER} = 'boot';
$ENV{THREESCALE_CONFIG_FILE} = 't/servroot/html/config.json';

Expand All @@ -17,8 +12,6 @@ env_to_nginx(
);

log_level('warn');
repeat_each(2);
no_root_location();
run_tests();

__DATA__
Expand Down
19 changes: 5 additions & 14 deletions t/013-configuration-loading-lazy.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use Test::Nginx::Socket 'no_plan';
use Cwd qw(cwd);
use lib 't';
use TestAPIcast 'no_plan';

my $pwd = cwd();
my $apicast = $ENV{TEST_NGINX_APICAST_PATH} || "$pwd/apicast";
$ENV{TEST_NGINX_HTTP_CONFIG} = "$TestAPIcast::path/http.d/init.conf";

$ENV{TEST_NGINX_LUA_PATH} = "$apicast/src/?.lua;;";
$ENV{TEST_NGINX_HTTP_CONFIG} = "$apicast/http.d/init.conf";
$ENV{TEST_NGINX_UPSTREAM_CONFIG} = "$apicast/http.d/upstream.conf";
$ENV{TEST_NGINX_APICAST_CONFIG} = "$apicast/conf.d/apicast.conf";
$ENV{TEST_NGINX_BACKEND_CONFIG} = "$apicast/conf.d/backend.conf";
$ENV{TEST_NGINX_APICAST_PATH} = $apicast;
$ENV{APICAST_CONFIGURATION_LOADER} = 'lazy';

env_to_nginx(
Expand All @@ -19,9 +12,7 @@ env_to_nginx(
'THREESCALE_PORTAL_ENDPOINT'
);

log_level('debug');
repeat_each(1);
no_root_location();
run_tests();

__DATA__
Expand Down Expand Up @@ -92,9 +83,9 @@ GET /t?user_key=fake
"id": 1,
"backend_version": 1,
"proxy": {
"api_backend": "http://127.0.0.1:$ENV{TEST_NGINX_SERVER_PORT}/api/",
"api_backend": "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient/api/",
"backend": {
"endpoint": "http://127.0.0.1:$ENV{TEST_NGINX_SERVER_PORT}"
"endpoint": "http://127.0.0.1:$Test::Nginx::Util::ServerPortForClient"
},
"proxy_rules": [
{ "pattern": "/t", "http_method": "GET", "metric_system_name": "test" }
Expand Down
Loading