2
0

route-domain.t 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. "upstream": {
  34. "nodes": {
  35. "127.0.0.1:1980": 1,
  36. "www.apiseven.com:80": 0
  37. },
  38. "type": "roundrobin"
  39. },
  40. "uri": "/hello"
  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 route
  60. --- request
  61. GET /hello
  62. --- response_body
  63. hello world
  64. --- error_log eval
  65. qr/dns resolver domain: www.apiseven.com to \d+.\d+.\d+.\d+/
  66. --- timeout: 10
  67. === TEST 4: set route(id: 1, using `rewrite` mode to pass upstream host)
  68. --- config
  69. location /t {
  70. content_by_lua_block {
  71. local t = require("lib.test_admin").test
  72. local code, body = t('/apisix/admin/routes/1',
  73. ngx.HTTP_PUT,
  74. [[{
  75. "upstream": {
  76. "nodes": {
  77. "127.0.0.1:1980": 1
  78. },
  79. "type": "roundrobin",
  80. "pass_host": "rewrite",
  81. "upstream_host": "test.com"
  82. },
  83. "uri": "/echo"
  84. }]]
  85. )
  86. if code >= 300 then
  87. ngx.status = code
  88. end
  89. ngx.say(body)
  90. }
  91. }
  92. --- request
  93. GET /t
  94. --- response_body
  95. passed
  96. === TEST 5: hit route
  97. --- request
  98. GET /echo
  99. --- response_headers
  100. host: test.com
  101. === TEST 6: set route(id: 1, using `node` mode to pass upstream host)
  102. --- config
  103. location /t {
  104. content_by_lua_block {
  105. local t = require("lib.test_admin").test
  106. local code, body = t('/apisix/admin/routes/1',
  107. ngx.HTTP_PUT,
  108. [[{
  109. "upstream": {
  110. "nodes": {
  111. "test.com:1980": 1
  112. },
  113. "type": "roundrobin",
  114. "desc": "new upstream",
  115. "pass_host": "node"
  116. },
  117. "uri": "/echo"
  118. }]]
  119. )
  120. if code >= 300 then
  121. ngx.status = code
  122. end
  123. ngx.say(body)
  124. }
  125. }
  126. --- request
  127. GET /t
  128. --- response_body
  129. passed
  130. === TEST 7: hit route
  131. --- request
  132. GET /echo
  133. --- response_headers
  134. host: test.com:1980
  135. === TEST 8: test domain with roundrobin
  136. --- config
  137. location /t {
  138. content_by_lua_block {
  139. local t = require("lib.test_admin").test
  140. local code, body = t('/apisix/admin/routes/1',
  141. ngx.HTTP_PUT,
  142. [[{
  143. "upstream": {
  144. "nodes": {
  145. "localhost:1981": 2,
  146. "127.0.0.1:1980": 1
  147. },
  148. "type": "roundrobin"
  149. },
  150. "uri": "/server_port"
  151. }]]
  152. )
  153. if code >= 300 then
  154. ngx.status = code
  155. end
  156. ngx.say(body)
  157. }
  158. }
  159. --- request
  160. GET /t
  161. --- response_body
  162. passed
  163. === TEST 9: hit
  164. --- config
  165. location /t {
  166. content_by_lua_block {
  167. local t = require("lib.test_admin").test
  168. local bodys = {}
  169. for i = 1, 3 do
  170. local _, _, body = t('/server_port', ngx.HTTP_GET)
  171. bodys[i] = body
  172. end
  173. table.sort(bodys)
  174. ngx.say(table.concat(bodys, ", "))
  175. }
  176. }
  177. --- request
  178. GET /t
  179. --- response_body
  180. 1980, 1981, 1981