service-empty.t 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 empty service. (id: 1)(allow empty `service` object)
  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/services/1',
  31. ngx.HTTP_PUT,
  32. '{}'
  33. )
  34. if code >= 300 then
  35. ngx.status = code
  36. end
  37. ngx.say(body)
  38. }
  39. }
  40. --- request
  41. GET /t
  42. --- response_body
  43. passed
  44. === TEST 2: route binding empty service
  45. --- config
  46. location /t {
  47. content_by_lua_block {
  48. local t = require("lib.test_admin").test
  49. local code, body = t('/apisix/admin/routes/1',
  50. ngx.HTTP_PUT,
  51. [[{
  52. "methods": ["GET"],
  53. "upstream": {
  54. "nodes": {
  55. "127.0.0.1:1980": 1
  56. },
  57. "type": "roundrobin"
  58. },
  59. "service_id": "1",
  60. "uri": "/hello"
  61. }]]
  62. )
  63. if code >= 300 then
  64. ngx.status = code
  65. end
  66. ngx.say(body)
  67. }
  68. }
  69. --- request
  70. GET /t
  71. --- response_body
  72. passed
  73. === TEST 3: /hello
  74. --- request
  75. GET /hello
  76. --- response_body
  77. hello world