invalid-upstream.t 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. no_long_string();
  21. no_root_location();
  22. no_shuffle();
  23. run_tests();
  24. __DATA__
  25. === TEST 1: set invalid upstream(id: 1)
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local core = require("apisix.core")
  30. local res, err = core.etcd.set("/upstreams/1", [[mexxxxxxxxxxxxxxx]])
  31. if res.status >= 300 then
  32. res.status = code
  33. end
  34. ngx.print(require("toolkit.json").encode(res.body))
  35. ngx.sleep(1)
  36. }
  37. }
  38. --- request
  39. GET /t
  40. --- wait: 1
  41. --- grep_error_log eval
  42. qr/\[error\].*/
  43. --- grep_error_log_out eval
  44. qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  45. --- response_body_like eval
  46. qr/"value":"mexxxxxxxxxxxxxxx"/
  47. === TEST 2: /not_found
  48. --- request
  49. GET /not_found
  50. --- error_code: 404
  51. --- response_body
  52. {"error_msg":"404 Route Not Found"}
  53. --- wait: 1
  54. --- grep_error_log eval
  55. qr/\[error\].*/
  56. --- grep_error_log_out eval
  57. qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  58. === TEST 3: delete invalid upstream(id: 1)
  59. --- config
  60. location /t {
  61. content_by_lua_block {
  62. local core = require("apisix.core")
  63. local res, err = core.etcd.delete("/upstreams/1")
  64. if res.status >= 300 then
  65. res.status = code
  66. end
  67. ngx.say("passed")
  68. ngx.sleep(1)
  69. }
  70. }
  71. --- request
  72. GET /t
  73. --- response_body
  74. passed
  75. --- grep_error_log eval
  76. qr/\[error\].*/
  77. --- grep_error_log_out eval
  78. qr{invalid item data of \[/apisix/upstreams/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  79. === TEST 4: set valid upstream(id: 1)
  80. --- config
  81. location /t {
  82. content_by_lua_block {
  83. local core = require("apisix.core")
  84. local res, err = core.etcd.set("/upstreams/1", core.json.decode([[{
  85. "nodes": {
  86. "127.0.0.1:1980": 1
  87. },
  88. "type": "roundrobin"
  89. }]]))
  90. if res.status >= 300 then
  91. res.status = code
  92. end
  93. ngx.print(require("toolkit.json").encode(res.body))
  94. ngx.sleep(1)
  95. }
  96. }
  97. --- request
  98. GET /t
  99. --- response_body_like eval
  100. qr/"nodes":\{"127.0.0.1:1980":1\}/
  101. === TEST 5: no error log
  102. --- config
  103. location /t {
  104. content_by_lua_block {
  105. ngx.sleep(1)
  106. ngx.say("done")
  107. }
  108. }
  109. --- request
  110. GET /t
  111. --- response_body
  112. done