route_with_uri_uris_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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("test route with valid uri uris",
  24. func(tc base.HttpTestCase) {
  25. base.RunTestCase(tc)
  26. },
  27. Entry("add route with valid uri", base.HttpTestCase{
  28. Object: base.ManagerApiExpect(),
  29. Path: "/apisix/admin/routes/r1",
  30. Method: http.MethodPut,
  31. Body: `{
  32. "name": "route1",
  33. "uri": "/hello",
  34. "upstream": {
  35. "nodes": {
  36. "` + base.UpstreamIp + `:1980": 1
  37. },
  38. "type": "roundrobin"
  39. }
  40. }`,
  41. Headers: map[string]string{"Authorization": base.GetToken()},
  42. ExpectStatus: http.StatusOK,
  43. }),
  44. Entry("hit the route (r1)", base.HttpTestCase{
  45. Object: base.APISIXExpect(),
  46. Method: http.MethodGet,
  47. Path: "/hello",
  48. Headers: map[string]string{"Authorization": base.GetToken()},
  49. ExpectStatus: http.StatusOK,
  50. ExpectBody: "hello world",
  51. Sleep: base.SleepTime,
  52. }),
  53. Entry("delete the route (r1)", base.HttpTestCase{
  54. Object: base.ManagerApiExpect(),
  55. Method: http.MethodDelete,
  56. Path: "/apisix/admin/routes/r1",
  57. Headers: map[string]string{"Authorization": base.GetToken()},
  58. ExpectStatus: http.StatusOK,
  59. Sleep: base.SleepTime,
  60. }),
  61. Entry("hit the route just delete", base.HttpTestCase{
  62. Object: base.APISIXExpect(),
  63. Method: http.MethodGet,
  64. Path: "/hello",
  65. Headers: map[string]string{"Authorization": base.GetToken()},
  66. ExpectStatus: http.StatusNotFound,
  67. ExpectBody: `{"error_msg":"404 Route Not Found"}`,
  68. Sleep: base.SleepTime,
  69. }),
  70. Entry("add route with valid uris", base.HttpTestCase{
  71. Object: base.ManagerApiExpect(),
  72. Method: http.MethodPut,
  73. Path: "/apisix/admin/routes/r1",
  74. Body: `{
  75. "name": "route1",
  76. "uris": ["/hello","/status"],
  77. "upstream": {
  78. "type": "roundrobin",
  79. "nodes": {
  80. "` + base.UpstreamIp + `:1980": 1
  81. }
  82. }
  83. }`,
  84. Headers: map[string]string{"Authorization": base.GetToken()},
  85. ExpectStatus: http.StatusOK,
  86. }),
  87. Entry("hit the route (/hello)", base.HttpTestCase{
  88. Object: base.APISIXExpect(),
  89. Method: http.MethodGet,
  90. Path: "/hello",
  91. Headers: map[string]string{"Authorization": base.GetToken()},
  92. ExpectStatus: http.StatusOK,
  93. ExpectBody: "hello world",
  94. Sleep: base.SleepTime,
  95. }),
  96. Entry("hit the route (/status)", base.HttpTestCase{
  97. Object: base.APISIXExpect(),
  98. Method: http.MethodGet,
  99. Path: "/status",
  100. Headers: map[string]string{"Authorization": base.GetToken()},
  101. ExpectStatus: http.StatusOK,
  102. ExpectBody: "ok",
  103. Sleep: base.SleepTime,
  104. }),
  105. Entry("delete the route (r1)", base.HttpTestCase{
  106. Object: base.ManagerApiExpect(),
  107. Method: http.MethodDelete,
  108. Path: "/apisix/admin/routes/r1",
  109. Headers: map[string]string{"Authorization": base.GetToken()},
  110. ExpectStatus: http.StatusOK,
  111. Sleep: base.SleepTime,
  112. }),
  113. Entry("hit the route just delete", base.HttpTestCase{
  114. Object: base.APISIXExpect(),
  115. Method: http.MethodGet,
  116. Path: "/hello",
  117. Headers: map[string]string{"Authorization": base.GetToken()},
  118. ExpectStatus: http.StatusNotFound,
  119. ExpectBody: `{"error_msg":"404 Route Not Found"}`,
  120. Sleep: base.SleepTime,
  121. }),
  122. )