spacewander commented on a change in pull request #5011:
URL: https://github.com/apache/apisix/pull/5011#discussion_r705821295
##########
File path: apisix/control/v1.lua
##########
@@ -156,6 +156,42 @@ function _M.get_health_checker()
return 200, info
end
+local function iter_add_get_routes_info(values, route_id)
+ local infos = {}
+ for _, route in core.config_util.iterate_values(values) do
+ local new_route = core.table.deepcopy(route)
+ if new_route.value.upstream and new_route.value.upstream.parent then
+ new_route.value.upstream.parent = nil
+ end
+ core.table.insert(infos, new_route)
+ if route_id and route.value.id == route_id then
+ return new_route, true
+ end
+ end
+ if not route_id then
+ return infos, true
+ end
+ return nil, false
Review comment:
We don't need a flag, just check the first result is nil or not
##########
File path: t/control/routes.t
##########
@@ -0,0 +1,171 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->yaml_config) {
+ my $yaml_config = <<_EOC_;
+apisix:
+ node_listen: 1984
+ config_center: yaml
+ enable_admin: false
+_EOC_
+
+ $block->set_value("yaml_config", $yaml_config);
+ }
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: routes
+--- apisix_yaml
+routes:
+ -
+ id: 1
+ uris:
+ - /hello
+ upstream:
+ nodes:
+ "127.0.0.1:1980": 1
+ "127.0.0.1:1988": 1
+ type: roundrobin
+ checks:
+ active:
+ http_path: "/status"
+ host: "127.0.0.1"
+ healthy:
+ interval: 1
+ successes: 1
+ unhealthy:
+ interval: 1
+ http_failures: 1
+#END
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+ local code, body, res = t.test('/v1/routes',
+ ngx.HTTP_GET)
+ res = json.decode(res)
+ if res[1] then
+ local data = {}
+ data.uris = res[1].value.uris
Review comment:
Need to check the upstream part too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]