From 0f147aca9f97932517031a1cc0cc395050a8c2ba Mon Sep 17 00:00:00 2001 From: spacewander Date: Thu, 4 Feb 2021 18:23:14 +0800 Subject: [PATCH] test Signed-off-by: spacewander --- .travis/linux_openresty_common_runner.sh | 2 +- t/APISIX.pm | 16 ++++++++++++++++ t/core/etcd-auth-fail.t | 3 ++- t/core/etcd-auth.t | 3 ++- utils/centos7-ci.sh | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.travis/linux_openresty_common_runner.sh b/.travis/linux_openresty_common_runner.sh index fe50864ee34b..55d42dad15fd 100755 --- a/.travis/linux_openresty_common_runner.sh +++ b/.travis/linux_openresty_common_runner.sh @@ -142,7 +142,7 @@ script() { make lint && make license-check || exit 1 # APISIX_ENABLE_LUACOV=1 PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t - PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t + FLUSH_ETCD=1 PERL5LIB=.:$PERL5LIB prove -Itest-nginx/lib -r t } after_success() { diff --git a/t/APISIX.pm b/t/APISIX.pm index 7ea6384366f2..7295cdcba321 100644 --- a/t/APISIX.pm +++ b/t/APISIX.pm @@ -638,4 +638,20 @@ _EOC_ $block; }); +sub run_or_exit ($) { + my ($cmd) = @_; + my $output = `$cmd`; + if ($?) { + warn "$output"; + exit 1; + } +} + +add_cleanup_handler(sub { + if ($ENV{FLUSH_ETCD}) { + run_or_exit "etcdctl del --prefix /apisix"; + run_or_exit "./bin/apisix init_etcd"; + } +}); + 1; diff --git a/t/core/etcd-auth-fail.t b/t/core/etcd-auth-fail.t index 5b3d70482c51..e04eca8fb6c6 100644 --- a/t/core/etcd-auth-fail.t +++ b/t/core/etcd-auth-fail.t @@ -15,7 +15,8 @@ # limitations under the License. # BEGIN { - $ENV{"ETCD_ENABLE_AUTH"} = "false" + $ENV{"ETCD_ENABLE_AUTH"} = "false"; + delete $ENV{"FLUSH_ETCD"}; } use t::APISIX 'no_plan'; diff --git a/t/core/etcd-auth.t b/t/core/etcd-auth.t index 794013aaa864..e83fb9cff3b8 100644 --- a/t/core/etcd-auth.t +++ b/t/core/etcd-auth.t @@ -15,7 +15,8 @@ # limitations under the License. # BEGIN { - $ENV{"ETCD_ENABLE_AUTH"} = "true" + $ENV{"ETCD_ENABLE_AUTH"} = "true"; + delete $ENV{"FLUSH_ETCD"}; } use t::APISIX 'no_plan'; diff --git a/utils/centos7-ci.sh b/utils/centos7-ci.sh index 9ef6f858f99a..d0065ac00c97 100755 --- a/utils/centos7-ci.sh +++ b/utils/centos7-ci.sh @@ -64,7 +64,7 @@ run_case() { export_or_prefix ./utils/set-dns.sh # run test cases - prove -I./test-nginx/lib -I./ -r -s t/ + FLUSH_ETCD=1 prove -I./test-nginx/lib -I./ -r t/ } case_opt=$1