This is an automated email from the ASF dual-hosted git repository.

chenjunxu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 1997ad7  feat: rewrite e2e test(server_info_test) with ginkgo (#1550)
1997ad7 is described below

commit 1997ad7851ee258b22a04ba6dd222391b49efaad
Author: JinChen <[email protected]>
AuthorDate: Thu Mar 4 15:15:03 2021 +0800

    feat: rewrite e2e test(server_info_test) with ginkgo (#1550)
---
 .../e2enew/server_info/server_info_suite_test.go   |  34 +++++
 .../server_info}/server_info_test.go               | 141 ++++++++++-----------
 2 files changed, 98 insertions(+), 77 deletions(-)

diff --git a/api/test/e2enew/server_info/server_info_suite_test.go 
b/api/test/e2enew/server_info/server_info_suite_test.go
new file mode 100644
index 0000000..b5c1771
--- /dev/null
+++ b/api/test/e2enew/server_info/server_info_suite_test.go
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package server_info
+
+import (
+       "testing"
+       "time"
+
+       "github.com/onsi/ginkgo"
+
+       "e2enew/base"
+)
+
+func TestRoute(t *testing.T) {
+       ginkgo.RunSpecs(t, "server info suite")
+}
+
+var _ = ginkgo.AfterSuite(func() {
+       time.Sleep(base.SleepTime)
+})
diff --git a/api/test/e2e/server_info_test.go 
b/api/test/e2enew/server_info/server_info_test.go
similarity index 52%
rename from api/test/e2e/server_info_test.go
rename to api/test/e2enew/server_info/server_info_test.go
index 74693fc..3a0fe0d 100644
--- a/api/test/e2e/server_info_test.go
+++ b/api/test/e2enew/server_info/server_info_test.go
@@ -14,127 +14,114 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package e2e
+package server_info
 
 import (
        "net/http"
-       "testing"
        "time"
+
+       "github.com/onsi/ginkgo"
+       "github.com/onsi/ginkgo/extensions/table"
+
+       "e2enew/base"
 )
 
-func TestServerInfo_Get(t *testing.T) {
-       // wait for apisix report
-       time.Sleep(2 * time.Second)
-       testCases := []HttpTestCase{
-               {
-                       Desc:         "get server info",
-                       Object:       ManagerApiExpect(t),
+var _ = ginkgo.Describe("server info test", func() {
+       table.DescribeTable("get server info",
+               func(tc base.HttpTestCase) {
+                       time.Sleep(2 * time.Second)
+                       base.RunTestCase(tc)
+               },
+               table.Entry("get server info(apisix-server1)", 
base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         
"/apisix/admin/server_info/apisix-server1",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"hostname\":\"apisix_server1\"",
-               },
-               {
-                       Desc:         "get server info",
-                       Object:       ManagerApiExpect(t),
+               }),
+               table.Entry("get server info(apisix-server2)", 
base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         
"/apisix/admin/server_info/apisix-server2",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"hostname\":\"apisix_server2\"",
-               },
-       }
+               }),
+       )
 
-       for _, tc := range testCases {
-               testCaseCheck(tc, t)
-       }
-}
-
-func TestServerInfo_List(t *testing.T) {
-       testCases := []HttpTestCase{
-               {
-                       Desc:         "list all server info",
-                       Object:       ManagerApiExpect(t),
+       table.DescribeTable("get server info list",
+               func(tc base.HttpTestCase) {
+                       base.RunTestCase(tc)
+               },
+               table.Entry("list all server info", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         "/apisix/admin/server_info",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"total_size\":2",
-               },
-               {
-                       Desc:         "list server info with hostname",
-                       Object:       ManagerApiExpect(t),
+               }),
+               table.Entry("list server info with hostname", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         "/apisix/admin/server_info",
                        Query:        "hostname=apisix_",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"total_size\":2",
-               },
-               {
-                       Desc:         "list server info with hostname",
-                       Object:       ManagerApiExpect(t),
+               }),
+               table.Entry("list server info with hostname", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         "/apisix/admin/server_info",
                        Query:        "hostname=apisix_server2",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"total_size\":1",
-               },
-       }
-
-       for _, tc := range testCases {
-               testCaseCheck(tc, t)
-       }
-}
+               }),
+       )
+})
 
-func TestServerInfo_Get_OmitEmptyValue(t *testing.T) {
-       // wait for apisix report
-       time.Sleep(2 * time.Second)
-       testCases := []HttpTestCase{
-               {
-                       Desc:         "get server info",
-                       Object:       ManagerApiExpect(t),
+var _ = ginkgo.Describe("server info test omitEmptyValue", func() {
+       table.DescribeTable("server info get omitEmptyValue",
+               func(tc base.HttpTestCase) {
+                       time.Sleep(2 * time.Second)
+                       base.RunTestCase(tc)
+               },
+               table.Entry("get server info", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         
"/apisix/admin/server_info/apisix-server1",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        UnexpectBody: []string{"\"create_time\":", 
"\"update_time\":"},
-               },
-       }
+               }),
+       )
 
-       for _, tc := range testCases {
-               testCaseCheck(tc, t)
-       }
-}
-
-func TestServerInfo_List_OmitEmptyValue(t *testing.T) {
-       testCases := []HttpTestCase{
-               {
-                       Desc:         "list all server info",
-                       Object:       ManagerApiExpect(t),
+       table.DescribeTable("server info list omitEmptyValue",
+               func(tc base.HttpTestCase) {
+                       base.RunTestCase(tc)
+               },
+               table.Entry("list all server info", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         "/apisix/admin/server_info",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"total_size\":2",
                        UnexpectBody: []string{"\"create_time\":", 
"\"update_time\":"},
-               },
-               {
-                       Desc:         "list server info with hostname",
-                       Object:       ManagerApiExpect(t),
+               }),
+               table.Entry("list server info with hostname", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Path:         "/apisix/admin/server_info",
                        Query:        "hostname=apisix_",
                        Method:       http.MethodGet,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   "\"total_size\":2",
                        UnexpectBody: []string{"\"create_time\":", 
"\"update_time\":"},
-               },
-       }
+               }),
+       )
 
-       for _, tc := range testCases {
-               testCaseCheck(tc, t)
-       }
-}
+})

Reply via email to