invalid-service.t 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 service(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("/services/1", [[mexxxxxxxxxxxxxxx]])
  31. if res.status >= 300 then
  32. ngx.status = code
  33. return ngx.say(res.body)
  34. end
  35. ngx.print(require("toolkit.json").encode(res.body))
  36. ngx.sleep(1)
  37. }
  38. }
  39. --- request
  40. GET /t
  41. --- wait: 1
  42. --- grep_error_log eval
  43. qr/\[error\].*/
  44. --- grep_error_log_out eval
  45. qr{invalid item data of \[/apisix/services/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  46. --- response_body_like eval
  47. qr/"value":"mexxxxxxxxxxxxxxx"/
  48. === TEST 2: try /not_found, got error log
  49. --- request
  50. GET /not_found
  51. --- error_code: 404
  52. --- response_body
  53. {"error_msg":"404 Route Not Found"}
  54. --- wait: 1
  55. --- grep_error_log eval
  56. qr/\[error\].*/
  57. --- grep_error_log_out eval
  58. qr{invalid item data of \[/apisix/services/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  59. === TEST 3: set valid service(id: 1), cover the old one
  60. --- config
  61. location /t {
  62. content_by_lua_block {
  63. local core = require("apisix.core")
  64. local res, err = core.etcd.set("/services/1", core.json.decode([[{
  65. "upstream": {
  66. "nodes": {
  67. "127.0.0.1:1980": 1
  68. },
  69. "type": "roundrobin"
  70. }
  71. }]]))
  72. if res.status >= 300 then
  73. ngx.status = code
  74. end
  75. ngx.print(require("toolkit.json").encode(res.body))
  76. }
  77. }
  78. --- request
  79. GET /t
  80. --- ret_code: 200
  81. --- response_body_like eval
  82. qr/"nodes":\{"127.0.0.1:1980":1\}/
  83. --- grep_error_log eval
  84. qr/\[error\].*/
  85. --- grep_error_log_out eval
  86. qr{invalid item data of \[/apisix/services/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  87. === TEST 4: no error log
  88. --- config
  89. location /t {
  90. content_by_lua_block {
  91. ngx.sleep(1)
  92. ngx.say("done")
  93. }
  94. }
  95. --- request
  96. GET /t
  97. --- response_body
  98. done