bisakh

server_info_test.go

Mar 21st, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 5.61 KB | None | 0 0
  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
  18.  
  19. import (
  20.     "github.com/onsi/ginkgo"
  21.     "github.com/onsi/ginkgo/extensions/table"
  22.     "net/http"
  23.     "time"
  24.  
  25.     "github.com/apisix/manager-api/test/e2enew/base"
  26. )
  27.  
  28. var _ = ginkgo.Describe("server info test", func() {
  29.     table.DescribeTable("get server info",
  30.         func(tc base.HttpTestCase) {
  31.             time.Sleep(2 * time.Second)
  32.             base.RunTestCase(tc)
  33.         },
  34.         table.Entry("get server info(apisix-server1)", base.HttpTestCase{
  35.             Object:       base.ManagerApiExpect(),
  36.             Path:         "/apisix/admin/server_info/apisix-server1",
  37.             Method:       http.MethodGet,
  38.             Headers:      map[string]string{"Authorization": base.GetToken()},
  39.             ExpectStatus: http.StatusOK,
  40.             ExpectBody:   "\"hostname\":\"apisix_server1\"",
  41.         }),
  42.         table.Entry("get server info(apisix-server2)", base.HttpTestCase{
  43.             Object:       base.ManagerApiExpect(),
  44.             Path:         "/apisix/admin/server_info/apisix-server2",
  45.             Method:       http.MethodGet,
  46.             Headers:      map[string]string{"Authorization": base.GetToken()},
  47.             ExpectStatus: http.StatusOK,
  48.             ExpectBody:   "\"hostname\":\"apisix_server2\"",
  49.         }),
  50.     //)
  51.     //
  52.     //table.DescribeTable("get server info list",
  53.     //  func(tc base.HttpTestCase) {
  54.     //      base.RunTestCase(tc)
  55.     //  },
  56.         table.Entry("list all server info", base.HttpTestCase{
  57.             Object:       base.ManagerApiExpect(),
  58.             Path:         "/apisix/admin/server_info",
  59.             Method:       http.MethodGet,
  60.             Headers:      map[string]string{"Authorization": base.GetToken()},
  61.             ExpectStatus: http.StatusOK,
  62.             ExpectBody:   "\"total_size\":2",
  63.         }),
  64.         table.Entry("list server info with hostname", base.HttpTestCase{
  65.             Object:       base.ManagerApiExpect(),
  66.             Path:         "/apisix/admin/server_info",
  67.             Query:        "hostname=apisix_",
  68.             Method:       http.MethodGet,
  69.             Headers:      map[string]string{"Authorization": base.GetToken()},
  70.             ExpectStatus: http.StatusOK,
  71.             ExpectBody:   "\"total_size\":2",
  72.         }),
  73.         table.Entry("list server info with hostname", base.HttpTestCase{
  74.             Object:       base.ManagerApiExpect(),
  75.             Path:         "/apisix/admin/server_info",
  76.             Query:        "hostname=apisix_server2",
  77.             Method:       http.MethodGet,
  78.             Headers:      map[string]string{"Authorization": base.GetToken()},
  79.             ExpectStatus: http.StatusOK,
  80.             ExpectBody:   "\"total_size\":1",
  81.         }),
  82. //  )
  83. //})
  84. //
  85. //var _ = ginkgo.Describe("server info test omitEmptyValue", func() {
  86. //  table.DescribeTable("server info get omitEmptyValue",
  87. //      func(tc base.HttpTestCase) {
  88. //          time.Sleep(2 * time.Second)
  89. //          base.RunTestCase(tc)
  90. //      },
  91.         table.Entry("get server info", base.HttpTestCase{
  92.             Object:       base.ManagerApiExpect(),
  93.             Path:         "/apisix/admin/server_info/apisix-server1",
  94.             Method:       http.MethodGet,
  95.             Headers:      map[string]string{"Authorization": base.GetToken()},
  96.             ExpectStatus: http.StatusOK,
  97.             UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
  98.         }),
  99.     //)
  100.     //
  101.     //table.DescribeTable("server info list omitEmptyValue",
  102.     //  func(tc base.HttpTestCase) {
  103.     //      base.RunTestCase(tc)
  104.     //  },
  105.         table.Entry("list all server info", base.HttpTestCase{
  106.             Object:       base.ManagerApiExpect(),
  107.             Path:         "/apisix/admin/server_info",
  108.             Method:       http.MethodGet,
  109.             Headers:      map[string]string{"Authorization": base.GetToken()},
  110.             ExpectStatus: http.StatusOK,
  111.             ExpectBody:   "\"total_size\":2",
  112.             UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
  113.         }),
  114.         table.Entry("list server info with hostname", base.HttpTestCase{
  115.             Object:       base.ManagerApiExpect(),
  116.             Path:         "/apisix/admin/server_info",
  117.             Query:        "hostname=apisix_",
  118.             Method:       http.MethodGet,
  119.             Headers:      map[string]string{"Authorization": base.GetToken()},
  120.             ExpectStatus: http.StatusOK,
  121.             ExpectBody:   "\"total_size\":2",
  122.             UnexpectBody: []string{"\"create_time\":", "\"update_time\":"},
  123.         }),
  124.         table.Entry("delete 0", base.HttpTestCase{
  125.             Object:       base.ManagerApiExpect(),
  126.             Method:        http.MethodDelete,
  127.             Path:          "/apisix/admin/server_info/apisix-server1",
  128.             Headers:       map[string]string{"Authorization": base.GetToken()},
  129.             ExpectStatus:  http.StatusOK,
  130.             ExpectCode:    0,
  131.             ExpectMessage: "Successful",
  132.         }),
  133.         table.Entry("delete 1", base.HttpTestCase{
  134.             Object:       base.ManagerApiExpect(),
  135.             Method:       http.MethodDelete,
  136.             Path:         "/apisix/admin/server_info/apisix-server1",
  137.             Headers:      map[string]string{"Authorization": base.GetToken()},
  138.             ExpectStatus: http.StatusNotFound,
  139.         }),
  140.         table.Entry("delete 2", base.HttpTestCase{
  141.             Object:       base.ManagerApiExpect(),
  142.             Method:       http.MethodDelete,
  143.             Path:         "/apisix/admin/server_info/apisix-server3",
  144.             Headers:      map[string]string{"Authorization": base.GetToken()},
  145.             ExpectStatus: http.StatusNotFound,
  146.         }),
  147.     )
  148.  
  149. })
  150.  
Advertisement
Add Comment
Please, Sign In to add comment