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

juzhiyuan 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 88f3232  feat: rewrite e2e test route with plugin orchestration test 
with ginkgo (#1663)
88f3232 is described below

commit 88f323285f2bdbafca027da9aef357b2e3eb4008
Author: JinChen <[email protected]>
AuthorDate: Thu Mar 25 15:52:06 2021 +0800

    feat: rewrite e2e test route with plugin orchestration test with ginkgo 
(#1663)
---
 api/test/e2enew/go.mod                             |   1 +
 api/test/e2enew/route/route_suite_test.go          |   2 +
 .../route}/route_with_plugin_orchestration_test.go | 104 ++++++++++-----------
 3 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/api/test/e2enew/go.mod b/api/test/e2enew/go.mod
index 33cb8d1..3897f34 100644
--- a/api/test/e2enew/go.mod
+++ b/api/test/e2enew/go.mod
@@ -7,6 +7,7 @@ require (
        github.com/gavv/httpexpect/v2 v2.1.0
        github.com/mattn/go-isatty v0.0.12 // indirect
        github.com/onsi/ginkgo v1.14.2
+       github.com/onsi/gomega v1.10.1 // indirect
        github.com/stretchr/testify v1.4.0
        github.com/tidwall/gjson v1.6.1
 )
diff --git a/api/test/e2enew/route/route_suite_test.go 
b/api/test/e2enew/route/route_suite_test.go
index ad10e5b..ff82374 100644
--- a/api/test/e2enew/route/route_suite_test.go
+++ b/api/test/e2enew/route/route_suite_test.go
@@ -21,11 +21,13 @@ import (
        "time"
 
        "github.com/onsi/ginkgo"
+       "github.com/onsi/gomega"
 
        "github.com/apisix/manager-api/test/e2enew/base"
 )
 
 func TestRoute(t *testing.T) {
+       gomega.RegisterFailHandler(ginkgo.Fail)
        ginkgo.RunSpecs(t, "route suite")
 }
 
diff --git a/api/test/e2e/route_with_plugin_orchestration_test.go 
b/api/test/e2enew/route/route_with_plugin_orchestration_test.go
similarity index 52%
rename from api/test/e2e/route_with_plugin_orchestration_test.go
rename to api/test/e2enew/route/route_with_plugin_orchestration_test.go
index e980c10..57e612e 100644
--- a/api/test/e2e/route_with_plugin_orchestration_test.go
+++ b/api/test/e2enew/route/route_with_plugin_orchestration_test.go
@@ -14,100 +14,98 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package e2e
+package route
 
 import (
        "io/ioutil"
        "net/http"
-       "testing"
 
-       "github.com/stretchr/testify/assert"
+       "github.com/onsi/ginkgo"
+       "github.com/onsi/ginkgo/extensions/table"
+       "github.com/onsi/gomega"
+
+       "github.com/apisix/manager-api/test/e2enew/base"
 )
 
-func TestRoute_With_Plugin_Orchestration(t *testing.T) {
-       bytes, err := ioutil.ReadFile("../testdata/dag-conf.json")
-       assert.Nil(t, err)
+var _ = ginkgo.Describe("route with plugin orchestration", func() {
+       bytes, err := ioutil.ReadFile("../../testdata/dag-conf.json")
+       ginkgo.It("panics if readfile dag-conf.json error", func() {
+               gomega.Expect(err).To(gomega.BeNil())
+       })
        dagConf := string(bytes)
 
        // invalid dag config that not specified root node
-       bytes, err = ioutil.ReadFile("../testdata/invalid-dag-conf.json")
-       assert.Nil(t, err)
+       bytes, err = ioutil.ReadFile("../../testdata/invalid-dag-conf.json")
+       ginkgo.It("panics if readfile invalid-dag-conf.json error", func() {
+               gomega.Expect(err).To(gomega.BeNil())
+       })
        invalidDagConf := string(bytes)
 
-       tests := []HttpTestCase{
-               {
-                       Desc:         "make sure the route is not created",
-                       Object:       APISIXExpect(t),
+       table.DescribeTable("test route with plugin orchestration",
+               func(tc base.HttpTestCase) {
+                       base.RunTestCase(tc)
+               },
+               table.Entry("make sure the route is not created", 
base.HttpTestCase{
+                       Object:       base.APISIXExpect(),
                        Method:       http.MethodGet,
                        Path:         "/hello",
                        ExpectStatus: http.StatusNotFound,
                        ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
-               },
-               {
-                       Desc:         "create route with invalid dag config",
-                       Object:       ManagerApiExpect(t),
+               }),
+               table.Entry("create route with invalid dag config", 
base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Method:       http.MethodPut,
                        Path:         "/apisix/admin/routes/r1",
                        Body:         invalidDagConf,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusBadRequest,
-               },
-               {
-                       Desc:         "make sure the route created failed",
-                       Object:       APISIXExpect(t),
+               }),
+               table.Entry("make sure the route created failed", 
base.HttpTestCase{
+                       Object:       base.APISIXExpect(),
                        Method:       http.MethodGet,
                        Path:         "/hello",
                        ExpectStatus: http.StatusNotFound,
                        ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
-                       Sleep:        sleepTime,
-               },
-               {
-                       Desc:         "create route with correct dag config",
-                       Object:       ManagerApiExpect(t),
+                       Sleep:        base.SleepTime,
+               }),
+               table.Entry("create route with correct dag config", 
base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Method:       http.MethodPut,
                        Path:         "/apisix/admin/routes/r1",
                        Body:         dagConf,
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
-               },
-               {
-                       Desc:         "verify the route(should be blocked)",
-                       Object:       APISIXExpect(t),
+               }),
+               table.Entry("verify the route(should be blocked)", 
base.HttpTestCase{
+                       Object:       base.APISIXExpect(),
                        Method:       http.MethodGet,
                        Path:         "/hello",
                        Query:        "t=root.exe",
                        ExpectStatus: http.StatusForbidden,
                        ExpectBody:   `blocked`,
-                       Sleep:        sleepTime,
-               },
-               {
-                       Desc:         "verify the route(should not be blocked)",
-                       Object:       APISIXExpect(t),
+                       Sleep:        base.SleepTime,
+               }),
+               table.Entry("verify the route(should not be blocked)", 
base.HttpTestCase{
+                       Object:       base.APISIXExpect(),
                        Method:       http.MethodGet,
                        Path:         "/hello",
                        ExpectStatus: http.StatusOK,
                        ExpectBody:   `hello world`,
-               },
-               {
-                       Desc:         "delete route",
-                       Object:       ManagerApiExpect(t),
+               }),
+               table.Entry("delete route", base.HttpTestCase{
+                       Object:       base.ManagerApiExpect(),
                        Method:       http.MethodDelete,
                        Path:         "/apisix/admin/routes/r1",
-                       Headers:      map[string]string{"Authorization": token},
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
                        ExpectStatus: http.StatusOK,
-               },
-               {
-                       Desc:         "hit the route just deleted",
-                       Object:       APISIXExpect(t),
+               }),
+               table.Entry("hit the route just deleted", base.HttpTestCase{
+                       Object:       base.APISIXExpect(),
                        Method:       http.MethodGet,
                        Path:         "/hello",
                        ExpectStatus: http.StatusNotFound,
                        ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
-                       Sleep:        sleepTime,
-               },
-       }
-
-       for _, tc := range tests {
-               testCaseCheck(tc, t)
-       }
-}
+                       Sleep:        base.SleepTime,
+               }),
+       )
+})

Reply via email to