consumer_with_labels_test.go 3.2 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. package consumer_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("Consumer With Labels",
  24. func(tc base.HttpTestCase) {
  25. base.RunTestCase(tc)
  26. },
  27. Entry("create the consumer", base.HttpTestCase{
  28. Object: base.ManagerApiExpect(),
  29. Method: http.MethodPut,
  30. Path: "/apisix/admin/consumers",
  31. Body: `{
  32. "username": "jack",
  33. "labels": {
  34. "build":"16",
  35. "env":"production",
  36. "version":"v2"
  37. },
  38. "plugins": {
  39. "key-auth": {
  40. "key": "auth-two"
  41. }
  42. },
  43. "desc": "test description"
  44. }`,
  45. Headers: map[string]string{"Authorization": base.GetToken()},
  46. ExpectStatus: http.StatusOK,
  47. }),
  48. Entry("verify the consumer", base.HttpTestCase{
  49. Object: base.ManagerApiExpect(),
  50. Method: http.MethodGet,
  51. Path: "/apisix/admin/consumers/jack",
  52. Headers: map[string]string{"Authorization": base.GetToken()},
  53. ExpectStatus: http.StatusOK,
  54. ExpectBody: "\"username\":\"jack\",\"desc\":\"test description\",\"plugins\":{\"key-auth\":{\"key\":\"auth-two\"}},\"labels\":{\"build\":\"16\",\"env\":\"production\",\"version\":\"v2\"}",
  55. }),
  56. Entry("create the route", base.HttpTestCase{
  57. Object: base.ManagerApiExpect(),
  58. Method: http.MethodPut,
  59. Path: "/apisix/admin/routes/r1",
  60. Body: `{
  61. "name": "route1",
  62. "uri": "/hello",
  63. "plugins": {
  64. "key-auth": {}
  65. },
  66. "upstream": {
  67. "type": "roundrobin",
  68. "nodes": [{
  69. "host": "` + base.UpstreamIp + `",
  70. "port": 1980,
  71. "weight": 1
  72. }]
  73. }
  74. }`,
  75. Headers: map[string]string{"Authorization": base.GetToken()},
  76. ExpectStatus: http.StatusOK,
  77. }),
  78. Entry("hit route", base.HttpTestCase{
  79. Object: base.APISIXExpect(),
  80. Method: http.MethodGet,
  81. Path: "/hello",
  82. Headers: map[string]string{"apikey": "auth-two"},
  83. ExpectStatus: http.StatusOK,
  84. }),
  85. Entry("delete consumer", base.HttpTestCase{
  86. Object: base.ManagerApiExpect(),
  87. Method: http.MethodDelete,
  88. Path: "/apisix/admin/consumers/jack",
  89. Headers: map[string]string{"Authorization": base.GetToken()},
  90. ExpectStatus: http.StatusOK,
  91. }),
  92. Entry("delete route", base.HttpTestCase{
  93. Object: base.ManagerApiExpect(),
  94. Method: http.MethodDelete,
  95. Path: "/apisix/admin/routes/r1",
  96. Headers: map[string]string{"Authorization": base.GetToken()},
  97. ExpectStatus: http.StatusOK,
  98. }),
  99. )