route_with_priority_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. package route_test
  18. import (
  19. "net/http"
  20. . "github.com/onsi/ginkgo/v2"
  21. "github.com/apisix/manager-api/test/e2e/base"
  22. )
  23. var _ = DescribeTable("route with priority test",
  24. func(tc base.HttpTestCase) {
  25. base.RunTestCase(tc)
  26. },
  27. Entry("add another route with no priority (default 0)", base.HttpTestCase{
  28. Object: base.ManagerApiExpect(),
  29. Method: http.MethodPut,
  30. Path: "/apisix/admin/routes/r1",
  31. Body: `{
  32. "name": "route1",
  33. "uri": "/server_port",
  34. "methods": ["GET"],
  35. "upstream": {
  36. "type": "roundrobin",
  37. "nodes": {
  38. "` + base.UpstreamIp + `:1981": 1
  39. }
  40. }
  41. }`,
  42. Headers: map[string]string{"Authorization": base.GetToken()},
  43. ExpectStatus: http.StatusOK,
  44. }),
  45. Entry("access the route", base.HttpTestCase{
  46. Object: base.APISIXExpect(),
  47. Method: http.MethodGet,
  48. Path: "/server_port",
  49. ExpectStatus: http.StatusOK,
  50. ExpectBody: "1981",
  51. Sleep: base.SleepTime,
  52. }),
  53. Entry("add another route with valid priority (1), upstream is different from the others", base.HttpTestCase{
  54. Object: base.ManagerApiExpect(),
  55. Method: http.MethodPut,
  56. Path: "/apisix/admin/routes/r2",
  57. Body: `{
  58. "name": "route2",
  59. "uri": "/server_port",
  60. "methods": ["GET"],
  61. "priority": 1,
  62. "upstream": {
  63. "type": "roundrobin",
  64. "nodes": {
  65. "` + base.UpstreamIp + `:1982": 1
  66. }
  67. }
  68. }`,
  69. Headers: map[string]string{"Authorization": base.GetToken()},
  70. ExpectStatus: http.StatusOK,
  71. }),
  72. Entry("access the route to determine whether it meets the priority (compare 1 and default)", base.HttpTestCase{
  73. Object: base.APISIXExpect(),
  74. Method: http.MethodGet,
  75. Path: "/server_port",
  76. ExpectStatus: http.StatusOK,
  77. ExpectBody: "1982",
  78. Sleep: base.SleepTime,
  79. }),
  80. Entry("delete route (r1)", base.HttpTestCase{
  81. Object: base.ManagerApiExpect(),
  82. Method: http.MethodDelete,
  83. Path: "/apisix/admin/routes/r1",
  84. Headers: map[string]string{"Authorization": base.GetToken()},
  85. ExpectStatus: http.StatusOK,
  86. Sleep: base.SleepTime,
  87. }),
  88. Entry("delete route (r2)", base.HttpTestCase{
  89. Object: base.ManagerApiExpect(),
  90. Method: http.MethodDelete,
  91. Path: "/apisix/admin/routes/r2",
  92. Headers: map[string]string{"Authorization": base.GetToken()},
  93. ExpectStatus: http.StatusOK,
  94. Sleep: base.SleepTime,
  95. }),
  96. Entry("hit the route just delete", base.HttpTestCase{
  97. Object: base.APISIXExpect(),
  98. Method: http.MethodGet,
  99. Path: "/server_port",
  100. ExpectStatus: http.StatusNotFound,
  101. ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
  102. Sleep: base.SleepTime,
  103. }),
  104. )