upstream-ipv6.t 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. add_block_preprocessor(sub {
  24. my $block = shift;
  25. $block->set_value("listen_ipv6", 1);
  26. });
  27. run_tests();
  28. __DATA__
  29. === TEST 1: set upstream(id: 1)
  30. --- config
  31. location /t {
  32. content_by_lua_block {
  33. local t = require("lib.test_admin").test
  34. local code, body = t('/apisix/admin/upstreams/1',
  35. ngx.HTTP_PUT,
  36. [[{
  37. "nodes": {
  38. "[::1]:1980": 1
  39. },
  40. "type": "roundrobin",
  41. "desc": "new upstream"
  42. }]]
  43. )
  44. if code >= 300 then
  45. ngx.status = code
  46. end
  47. ngx.say(body)
  48. }
  49. }
  50. --- request
  51. GET /t
  52. --- response_body
  53. passed
  54. === TEST 2: set route(id: 1)
  55. --- config
  56. location /t {
  57. content_by_lua_block {
  58. local t = require("lib.test_admin").test
  59. local code, body = t('/apisix/admin/routes/1',
  60. ngx.HTTP_PUT,
  61. [[{
  62. "uri": "/hello",
  63. "upstream_id": "1"
  64. }]]
  65. )
  66. if code >= 300 then
  67. ngx.status = code
  68. end
  69. ngx.say(body)
  70. }
  71. }
  72. --- request
  73. GET /t
  74. --- response_body
  75. passed
  76. === TEST 3: /not_found
  77. --- request
  78. GET /not_found
  79. --- error_code: 404
  80. --- response_body
  81. {"error_msg":"404 Route Not Found"}
  82. === TEST 4: hit routes
  83. --- request
  84. GET /hello
  85. --- response_body
  86. hello world
  87. === TEST 5: set upstream(id: 1)
  88. --- config
  89. location /t {
  90. content_by_lua_block {
  91. local t = require("lib.test_admin").test
  92. local code, body = t('/apisix/admin/upstreams/1',
  93. ngx.HTTP_PUT,
  94. [[{
  95. "nodes": [
  96. {
  97. "weight": 100,
  98. "priority": 0,
  99. "host": "::1",
  100. "port": 1980
  101. }
  102. ],
  103. "type": "roundrobin",
  104. "desc": "new upstream"
  105. }]]
  106. )
  107. if code >= 300 then
  108. ngx.status = code
  109. end
  110. ngx.say(body)
  111. }
  112. }
  113. --- request
  114. GET /t
  115. --- response_body
  116. passed
  117. === TEST 6: hit routes
  118. --- request
  119. GET /hello
  120. --- response_body
  121. hello world
  122. === TEST 7: set upstream, one array item to specify node
  123. --- config
  124. location /t {
  125. content_by_lua_block {
  126. local t = require("lib.test_admin").test
  127. local code, body = t('/apisix/admin/upstreams/1',
  128. ngx.HTTP_PUT,
  129. [[{
  130. "nodes": [
  131. {
  132. "weight": 100,
  133. "priority": 0,
  134. "host": "[::1]",
  135. "port": 1980
  136. }
  137. ],
  138. "type": "roundrobin",
  139. "desc": "new upstream"
  140. }]]
  141. )
  142. if code >= 300 then
  143. ngx.status = code
  144. end
  145. ngx.say(body)
  146. }
  147. }
  148. --- request
  149. GET /t
  150. --- response_body
  151. passed
  152. === TEST 8: hit routes
  153. --- request
  154. GET /hello
  155. --- response_body
  156. hello world
  157. === TEST 9: set upstream, one hash key to specify node, in wrong format
  158. --- config
  159. location /t {
  160. content_by_lua_block {
  161. local t = require("lib.test_admin").test
  162. local code, body = t('/apisix/admin/upstreams/1',
  163. ngx.HTTP_PUT,
  164. [[{
  165. "nodes": {
  166. "::1:1980": 1
  167. },
  168. "type": "roundrobin",
  169. "desc": "new upstream"
  170. }]]
  171. )
  172. if code >= 300 then
  173. ngx.status = code
  174. end
  175. ngx.say(body)
  176. }
  177. }
  178. --- request
  179. GET /t
  180. --- response_body
  181. passed
  182. === TEST 10: hit routes
  183. --- request
  184. GET /hello
  185. --- error_code: 502
  186. --- error_log
  187. connect() to [::0.1.25.128]:80 failed
  188. === TEST 11: set upstream, two array items to specify nodes
  189. --- config
  190. location /t {
  191. content_by_lua_block {
  192. local t = require("lib.test_admin").test
  193. local code, body = t('/apisix/admin/upstreams/1',
  194. ngx.HTTP_PUT,
  195. [[{
  196. "nodes": [
  197. {
  198. "weight": 100,
  199. "priority": 0,
  200. "host": "::1",
  201. "port": 1980
  202. },
  203. {
  204. "weight": 100,
  205. "priority": 0,
  206. "host": "::1",
  207. "port": 1980
  208. }
  209. ],
  210. "type": "roundrobin",
  211. "desc": "new upstream"
  212. }]]
  213. )
  214. if code >= 300 then
  215. ngx.status = code
  216. end
  217. ngx.say(body)
  218. }
  219. }
  220. --- request
  221. GET /t
  222. --- response_body
  223. passed
  224. === TEST 12: hit routes
  225. --- request
  226. GET /hello
  227. --- response_body
  228. hello world