server_info_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 server_info_test
  18. import (
  19. "net/http"
  20. "time"
  21. . "github.com/onsi/ginkgo/v2"
  22. "github.com/apisix/manager-api/test/e2e/base"
  23. )
  24. var _ = Describe("server info test", func() {
  25. DescribeTable("get server info",
  26. func(tc base.HttpTestCase) {
  27. time.Sleep(2 * time.Second)
  28. base.RunTestCase(tc)
  29. },
  30. Entry("get server info(apisix-server1)", base.HttpTestCase{
  31. Object: base.ManagerApiExpect(),
  32. Path: "/apisix/admin/server_info/apisix-server1",
  33. Method: http.MethodGet,
  34. Headers: map[string]string{"Authorization": base.GetToken()},
  35. ExpectStatus: http.StatusOK,
  36. ExpectBody: "\"hostname\":\"apisix_server1\"",
  37. }),
  38. Entry("get server info(apisix-server2)", base.HttpTestCase{
  39. Object: base.ManagerApiExpect(),
  40. Path: "/apisix/admin/server_info/apisix-server2",
  41. Method: http.MethodGet,
  42. Headers: map[string]string{"Authorization": base.GetToken()},
  43. ExpectStatus: http.StatusOK,
  44. ExpectBody: "\"hostname\":\"apisix_server2\"",
  45. }),
  46. )
  47. DescribeTable("get server info list",
  48. func(tc base.HttpTestCase) {
  49. base.RunTestCase(tc)
  50. },
  51. Entry("list all server info", base.HttpTestCase{
  52. Object: base.ManagerApiExpect(),
  53. Path: "/apisix/admin/server_info",
  54. Method: http.MethodGet,
  55. Headers: map[string]string{"Authorization": base.GetToken()},
  56. ExpectStatus: http.StatusOK,
  57. ExpectBody: "\"total_size\":2",
  58. }),
  59. Entry("list server info with hostname", base.HttpTestCase{
  60. Object: base.ManagerApiExpect(),
  61. Path: "/apisix/admin/server_info",
  62. Query: "hostname=apisix_",
  63. Method: http.MethodGet,
  64. Headers: map[string]string{"Authorization": base.GetToken()},
  65. ExpectStatus: http.StatusOK,
  66. ExpectBody: "\"total_size\":2",
  67. }),
  68. Entry("list server info with hostname", base.HttpTestCase{
  69. Object: base.ManagerApiExpect(),
  70. Path: "/apisix/admin/server_info",
  71. Query: "hostname=apisix_server2",
  72. Method: http.MethodGet,
  73. Headers: map[string]string{"Authorization": base.GetToken()},
  74. ExpectStatus: http.StatusOK,
  75. ExpectBody: "\"total_size\":1",
  76. }),
  77. )
  78. })
  79. var _ = Describe("server info test omitEmptyValue", func() {
  80. DescribeTable("server info get omitEmptyValue",
  81. func(tc base.HttpTestCase) {
  82. time.Sleep(2 * time.Second)
  83. base.RunTestCase(tc)
  84. },
  85. Entry("get server info", base.HttpTestCase{
  86. Object: base.ManagerApiExpect(),
  87. Path: "/apisix/admin/server_info/apisix-server1",
  88. Method: http.MethodGet,
  89. Headers: map[string]string{"Authorization": base.GetToken()},
  90. ExpectStatus: http.StatusOK,
  91. UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
  92. }),
  93. )
  94. DescribeTable("server info list omitEmptyValue",
  95. func(tc base.HttpTestCase) {
  96. base.RunTestCase(tc)
  97. },
  98. Entry("list all server info", base.HttpTestCase{
  99. Object: base.ManagerApiExpect(),
  100. Path: "/apisix/admin/server_info",
  101. Method: http.MethodGet,
  102. Headers: map[string]string{"Authorization": base.GetToken()},
  103. ExpectStatus: http.StatusOK,
  104. ExpectBody: "\"total_size\":2",
  105. UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
  106. }),
  107. Entry("list server info with hostname", base.HttpTestCase{
  108. Object: base.ManagerApiExpect(),
  109. Path: "/apisix/admin/server_info",
  110. Query: "hostname=apisix_",
  111. Method: http.MethodGet,
  112. Headers: map[string]string{"Authorization": base.GetToken()},
  113. ExpectStatus: http.StatusOK,
  114. ExpectBody: "\"total_size\":2",
  115. UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
  116. }),
  117. )
  118. })