@@ -140,6 +140,7 @@ location /consul3 {
140140 "PUT /consul1/deregister/service_b2",
141141 "PUT /consul1/deregister/service_a3",
142142 "PUT /consul1/deregister/service_a4",
143+ "PUT /consul1/deregister/service_no_port",
143144 "PUT /consul2/deregister/service_a1",
144145 "PUT /consul2/deregister/service_a2",
145146 "PUT /consul3/deregister/service_a1",
@@ -148,13 +149,14 @@ location /consul3 {
148149 "PUT /consul1/register\n" . "{\"ID\":\"service_a2\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30512,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
149150 "PUT /consul1/register\n" . "{\"ID\":\"service_a3\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"localhost\",\"Port\":30511,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
150151 "PUT /consul1/register\n" . "{\"ID\":\"service_a4\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"localhost\",\"Port\":30512,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
152+ "PUT /consul1/register\n" . "{\"ID\":\"service_no_port\",\"Name\":\"service_no_port\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Meta\":{\"service_version\":\"1.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
151153 "PUT /consul2/register\n" . "{\"ID\":\"service_a1\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30511,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
152154 "PUT /consul2/register\n" . "{\"ID\":\"service_a2\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30512,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
153155 "PUT /consul3/register\n" . "{\"ID\":\"service_a1\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30511,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
154156 "PUT /consul3/register\n" . "{\"ID\":\"service_a2\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30512,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
155157]
156158--- error_code eval
157- [200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200]
159+ [200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 ]
158160
159161
160162
@@ -187,7 +189,7 @@ discovery:
187189--- request
188190GET /t
189191--- response_body
190- {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"localhost","port":30512,"weight":1}]}
192+ {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"localhost","port":30512,"weight":1}],"service_no_port":[{"host":"127.0.0.1","port":80,"weight":1}] }
191193
192194
193195
@@ -221,7 +223,7 @@ discovery:
221223--- request
222224GET /t
223225--- response_body
224- {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"localhost","port":30512,"weight":1}]}
226+ {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"localhost","port":30512,"weight":1}],"service_no_port":[{"host":"127.0.0.1","port":80,"weight":1}] }
225227
226228
227229
@@ -255,7 +257,7 @@ discovery:
255257--- request
256258GET /t
257259--- response_body
258- {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30512,"weight":1}]}
260+ {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30512,"weight":1}],"service_no_port":[{"host":"127.0.0.1","port":80,"weight":1}] }
259261
260262
261263
@@ -289,4 +291,44 @@ discovery:
289291--- request
290292GET /t
291293--- response_body
292- {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"localhost","port":30512,"weight":1}]}
294+ {"service_a":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1},{"host":"localhost","port":30511,"weight":1},{"host":"localhost","port":30512,"weight":1}],"service_no_port":[{"host":"127.0.0.1","port":80,"weight":1}]}
295+
296+
297+
298+ === TEST 6: verify service without port defaults to port 80
299+ --- yaml_config
300+ apisix:
301+ node_listen: 1984
302+ enable_control: true
303+ discovery:
304+ consul:
305+ servers:
306+ - "http://127.0.0.1:9500"
307+ dump:
308+ path: "consul.dump"
309+ load_on_init: false
310+ --- config
311+ location /t {
312+ content_by_lua_block {
313+ local json = require("toolkit.json")
314+ local t = require("lib.test_admin")
315+ ngx.sleep(2)
316+
317+ local code, body, res = t.test('/v1/discovery/consul/show_dump_file',
318+ ngx.HTTP_GET)
319+ local entity = json.decode(res)
320+
321+ -- Check that service_no_port exists and has default port 80
322+ local service_no_port = entity.services.service_no_port
323+ if service_no_port and #service_no_port > 0 then
324+ ngx.say("service_no_port found with port: ", service_no_port[1].port)
325+ else
326+ ngx.say("service_no_port not found")
327+ end
328+ }
329+ }
330+ --- timeout: 3
331+ --- request
332+ GET /t
333+ --- response_body
334+ service_no_port found with port: 80
0 commit comments