membphis commented on a change in pull request #2036: URL: https://github.com/apache/apisix/pull/2036#discussion_r488008439
########## File path: t/core/etcd.t ########## @@ -0,0 +1,335 @@ +# +# 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(); +log_level("info"); + +run_tests; + +__DATA__ + +=== TEST 1: delete test data if exists +--- config + location /delete { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE) + ngx.status = code + ngx.say(body) + } + } +--- request +GET /delete +--- no_error_log +[error] +--- ignore_response + + + +=== TEST 2: (add + update + delete) *2 (same uri) +--- config + location /add { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "host": "foo.com", + "uri": "/hello" + }]], + nil + ) + ngx.status = code + ngx.say(body) + } + } + location /update { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "upstream": { + "nodes": { + "127.0.0.1:1980": 2 + }, + "type": "roundrobin" + }, + "host": "foo.com", + "uri": "/hello" + }]], + nil + ) + ngx.status = code + ngx.say(body) + } + } + location /delete { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE) + ngx.status = code + ngx.say(body) + } + } +--- pipelined_requests eval +["GET /add", "GET /hello", "GET /update", "GET /hello", "GET /delete", "GET /hello", Review comment: I rewrite `=== TEST 2: (add + update + delete) *2 (same uri)` right now, please confirm if it is acceptable. @Yiyiyimu @nic-chen ``` === TEST 2: create route(id: 1) --- config location /t { content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, [[{ "upstream": { "nodes": { "127.0.0.1:1980": 1 }, "type": "roundrobin" }, "host": "foo.com", "uri": "/hello" }]], nil ) ngx.status = code ngx.say(body) } } --- request GET /t --- error_code: 201 --- no_error_log [error] === TEST 3: missing route(no host) --- request GET /hello --- error_code: 404 --- no_error_log [error] === TEST 4: hit routes --- request GET /hello --- more_headers Host: foo.com --- response_body hello world --- no_error_log [error] === TEST 5: update route(host: foo2.com) --- config location /t { content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, [[{ "upstream": { "nodes": { "127.0.0.1:1980": 1 }, "type": "roundrobin" }, "host": "foo2.com", "uri": "/hello" }]], nil ) ngx.status = code ngx.say(body) } } --- request GET /t --- error_code: 200 --- no_error_log [error] === TEST 6: missing route(no host) --- request GET /hello --- more_headers Host: foo.com --- error_code: 404 --- no_error_log [error] === TEST 7: hit routes --- request GET /hello --- more_headers Host: foo2.com --- response_body hello world --- no_error_log [error] === TEST 8: delete route --- config location /t { content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE) ngx.status = code ngx.say(body) } } --- request GET /t --- error_code: 200 --- no_error_log [error] === TEST 9: hit nothing --- request GET /hello --- more_headers Host: foo2.com --- error_code: 404 --- no_error_log [error] ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
