route-domain-with-local-dns.t 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. BEGIN {
  18. # for test
  19. $ENV{ENABLE_LOCAL_DNS} = "true";
  20. }
  21. use t::APISIX 'no_plan';
  22. repeat_each(1);
  23. log_level('info');
  24. worker_connections(256);
  25. no_root_location();
  26. no_shuffle();
  27. run_tests();
  28. __DATA__
  29. === TEST 1: set route(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/routes/1',
  35. ngx.HTTP_PUT,
  36. [[{
  37. "upstream": {
  38. "nodes": {
  39. "127.0.0.1:1980": 1,
  40. "www.apiseven.com:80": 0
  41. },
  42. "type": "roundrobin"
  43. },
  44. "uri": "/hello"
  45. }]]
  46. )
  47. if code >= 300 then
  48. ngx.status = code
  49. end
  50. ngx.say(body)
  51. }
  52. }
  53. --- request
  54. GET /t
  55. --- response_body
  56. passed
  57. --- error_log eval
  58. qr/.*init_resolver\(\): dns resolver \[.+\]/
  59. === TEST 2: /not_found
  60. --- request
  61. GET /not_found
  62. --- error_code: 404
  63. --- response_body
  64. {"error_msg":"404 Route Not Found"}
  65. --- error_log eval
  66. qr/.*init_resolver\(\): dns resolver \[.+\]/
  67. === TEST 3: hit route
  68. --- request
  69. GET /hello
  70. --- response_body
  71. hello world
  72. --- error_log eval
  73. qr/dns resolver domain: www.apiseven.com to \d+.\d+.\d+.\d+/