not-exist-service.t 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: invalid service id
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local core = require("apisix.core")
  30. local res, err = core.etcd.set("/routes/1", {
  31. service_id = "999999999",
  32. uri = "/hello"
  33. })
  34. if res.status >= 300 then
  35. ngx.status = res.status
  36. return ngx.exit(res.status)
  37. end
  38. ngx.say("passed")
  39. }
  40. }
  41. --- request
  42. GET /t
  43. --- response_body
  44. passed
  45. === TEST 2: hit routes
  46. --- request
  47. GET /hello
  48. --- error_code: 404
  49. --- response_body eval
  50. qr/404 Not Found/
  51. --- wait_etcd_sync: 0.3
  52. --- grep_error_log eval
  53. qr/\[error\].*/
  54. --- grep_error_log_out eval
  55. qr/failed to fetch service configuration by id/
  56. === TEST 3: set valid route(id: 1)
  57. --- config
  58. location /t {
  59. content_by_lua_block {
  60. local t = require("lib.test_admin").test
  61. local code, body = t('/apisix/admin/routes/1',
  62. ngx.HTTP_PUT,
  63. [[{
  64. "upstream": {
  65. "nodes": {
  66. "127.0.0.1:1980": 1
  67. },
  68. "type": "roundrobin"
  69. },
  70. "uri": "/hello"
  71. }]]
  72. )
  73. if code >= 300 then
  74. ngx.status = code
  75. end
  76. ngx.say(body)
  77. }
  78. }
  79. --- request
  80. GET /t
  81. --- response_body
  82. passed
  83. === TEST 4: hit routes
  84. --- request
  85. GET /hello
  86. --- response_body
  87. hello world