sanity-radixtree.t 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. use t::APISIX 'no_plan';
  18. repeat_each(1);
  19. log_level('info');
  20. worker_connections(256);
  21. no_root_location();
  22. no_shuffle();
  23. run_tests();
  24. __DATA__
  25. === TEST 1: set route(id: 1)
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local t = require("lib.test_admin").test
  30. local code, body = t('/apisix/admin/routes/1',
  31. ngx.HTTP_PUT,
  32. [[{
  33. "methods": ["GET"],
  34. "uri": "/hello",
  35. "upstream": {
  36. "nodes": {
  37. "127.0.0.1:1980": 1
  38. },
  39. "type": "roundrobin"
  40. }
  41. }]]
  42. )
  43. if code >= 300 then
  44. ngx.status = code
  45. end
  46. ngx.say(body)
  47. }
  48. }
  49. --- request
  50. GET /t
  51. --- response_body
  52. passed
  53. === TEST 2: /not_found
  54. --- request
  55. GET /not_found
  56. --- error_code: 404
  57. --- response_body
  58. {"error_msg":"404 Route Not Found"}
  59. === TEST 3: hit routes
  60. --- request
  61. GET /hello
  62. --- response_body
  63. hello world
  64. === TEST 4: set route(id: 1)
  65. --- config
  66. location /t {
  67. content_by_lua_block {
  68. local t = require("lib.test_admin").test
  69. local code, body = t('/apisix/admin/routes/1',
  70. ngx.HTTP_PUT,
  71. [[{
  72. "upstream": {
  73. "nodes": {
  74. "127.0.0.1:1980": 1
  75. },
  76. "type": "roundrobin"
  77. },
  78. "uri": "/hello*"
  79. }]]
  80. )
  81. if code >= 300 then
  82. ngx.status = code
  83. end
  84. ngx.say(body)
  85. }
  86. }
  87. --- request
  88. GET /t
  89. --- response_body
  90. passed
  91. === TEST 5: hit routes:/hello
  92. --- request
  93. GET /hello
  94. --- response_body
  95. hello world
  96. === TEST 6: hit routes: /hello1
  97. --- request
  98. GET /hello1
  99. --- response_body
  100. hello1 world
  101. === TEST 7: hit routes: /hello2
  102. --- request
  103. GET /hello2
  104. --- error_code: 404
  105. --- response_body eval
  106. qr/404 Not Found/
  107. === TEST 8: hit routes: /hel
  108. --- request
  109. GET /hel
  110. --- error_code: 404
  111. --- response_body
  112. {"error_msg":"404 Route Not Found"}