You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/09/26 03:24:44 UTC

[apisix] branch master updated: test: fix config error in test cases (#7946)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 60abeffde test: fix config error in test cases (#7946)
60abeffde is described below

commit 60abeffde9f2a3da6f31e1f36ca2f2f20234bf84
Author: levy liu <37...@qq.com>
AuthorDate: Mon Sep 26 11:24:34 2022 +0800

    test: fix config error in test cases (#7946)
---
 apisix/core/config_local.lua | 8 ++++++--
 t/APISIX.pm                  | 7 +++++++
 t/plugin/redirect.t          | 4 ++--
 t/tars/discovery/tars.t      | 5 ++---
 4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/apisix/core/config_local.lua b/apisix/core/config_local.lua
index cf44feed1..1c17086dc 100644
--- a/apisix/core/config_local.lua
+++ b/apisix/core/config_local.lua
@@ -19,8 +19,9 @@
 --
 -- @module core.config_local
 
-local file = require("apisix.cli.file")
+local file   = require("apisix.cli.file")
 local schema = require("apisix.cli.schema")
+local error  = error
 
 
 local _M = {}
@@ -65,7 +66,10 @@ function _M.local_conf(force)
     end
 
     -- fill the default value by the schema
-    schema.validate(default_conf)
+    local ok, err = schema.validate(default_conf)
+    if not ok then
+        error(err)
+    end
 
     config_data = default_conf
     return config_data
diff --git a/t/APISIX.pm b/t/APISIX.pm
index 496bad4e1..2af517abd 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -493,6 +493,11 @@ _EOC_
 
     $block->set_value("main_config", $main_config);
 
+    # The new directive is introduced here to modify the schema
+    # before apisix validate in require("apisix")
+    # Todo: merge extra_init_by_lua_start and extra_init_by_lua
+    my $extra_init_by_lua_start = $block->extra_init_by_lua_start // "";
+
     my $extra_init_by_lua = $block->extra_init_by_lua // "";
     my $init_by_lua_block = $block->init_by_lua_block // <<_EOC_;
     if os.getenv("APISIX_ENABLE_LUACOV") == "1" then
@@ -502,6 +507,8 @@ _EOC_
 
     require "resty.core"
 
+    $extra_init_by_lua_start
+
     apisix = require("apisix")
     local args = {
         dns_resolver = $dns_addrs_tbl_str,
diff --git a/t/plugin/redirect.t b/t/plugin/redirect.t
index b46b02c37..4d4d4c5f7 100644
--- a/t/plugin/redirect.t
+++ b/t/plugin/redirect.t
@@ -477,8 +477,8 @@ apisix:
     ssl:
         enable: true
         listen:
-            - 6443
-            - 7443
+            - port: 6443
+            - port: 7443
             - port: 8443
             - port: 9443
 --- request
diff --git a/t/tars/discovery/tars.t b/t/tars/discovery/tars.t
index a64f4096b..9cc160664 100644
--- a/t/tars/discovery/tars.t
+++ b/t/tars/discovery/tars.t
@@ -54,9 +54,8 @@ _EOC_
 
     $block->set_value("apisix_yaml", $apisix_yaml);
 
-    my $extra_init_by_lua = <<_EOC_;
+    my $extra_init_by_lua_start = <<_EOC_;
         -- reduce incremental_fetch_interval,full_fetch_interval
-        local core = require("apisix.core")
         local schema = require("apisix.discovery.tars.schema")
         schema.properties.incremental_fetch_interval.minimum=1
         schema.properties.incremental_fetch_interval.default=1
@@ -64,7 +63,7 @@ _EOC_
         schema.properties.full_fetch_interval.default = 3
 _EOC_
 
-    $block->set_value("extra_init_by_lua", $extra_init_by_lua);
+    $block->set_value("extra_init_by_lua_start", $extra_init_by_lua_start);
 
     my $config = $block->config // <<_EOC_;
         location /count {