You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/04/04 12:54:19 UTC

[GitHub] [apisix-dashboard] bisakhmondal commented on a change in pull request #1704: feat: rewrite e2e test(test-e2e-route-with-management-fields) using ginkgo

bisakhmondal commented on a change in pull request #1704:
URL: https://github.com/apache/apisix-dashboard/pull/1704#discussion_r606797818



##########
File path: api/test/e2enew/route/route_with_management_fields_test.go
##########
@@ -0,0 +1,457 @@
+/*
+ * 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 route
+
+import (
+	"io/ioutil"
+	"net/http"
+	"time"
+
+	"github.com/onsi/ginkgo"
+	"github.com/onsi/ginkgo/extensions/table"
+	"github.com/onsi/gomega"
+	"github.com/tidwall/gjson"
+
+	"github.com/apisix/manager-api/test/e2enew/base"
+)
+
+var _ = ginkgo.Describe("route with management fields", func() {
+	var (
+		createtime, updatetime gjson.Result
+	)
+
+	table.DescribeTable("test for route with name description",
+		func(tc base.HttpTestCase) {
+			base.RunTestCase(tc)
+		},
+		table.Entry("config route with name and desc (r1)", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Path:   "/apisix/admin/routes/r1",
+			Method: http.MethodPut,
+			Body: `{
+					"name": "route1",
+					"uri": "/hello",
+					"name": "jack",
+					"desc": "config route with name and desc",
+					"upstream": {
+						"type": "roundrobin",
+						"nodes": [{
+							"host": "172.16.238.20",
+							"port": 1980,
+							"weight": 1
+						}]
+					}
+				}`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		}),
+		table.Entry("check route exists by name", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/notexist/routes",
+			Query:        "name=jack",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusBadRequest,
+			ExpectBody:   "Route name is reduplicate",
+			Sleep:        base.SleepTime,
+		}),
+		table.Entry("check route exists by name (exclude it self)", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/notexist/routes",
+			Query:        "name=jack&exclude=r1",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		}),
+		table.Entry("access the route's uri (r1)", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+		}),
+		table.Entry("verify the route's content (r1)", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Path:         "/apisix/admin/routes/r1",
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "\"name\":\"jack\",\"desc\":\"config route with name and desc\"",
+		}),
+	)
+
+	ginkgo.It("get the route information", func() {
+		time.Sleep(time.Duration(100) * time.Millisecond)
+		basepath := base.ManagerAPIHost + "/apisix/admin/routes"
+		request, _ := http.NewRequest("GET", basepath+"/r1", nil)
+		request.Header.Add("Authorization", base.GetToken())
+		resp, err := http.DefaultClient.Do(request)
+		if err != nil {
+			return
+		}
+		defer resp.Body.Close()
+		respBody, _ := ioutil.ReadAll(resp.Body)
+		createtime = gjson.Get(string(respBody), "data.create_time")
+		updatetime = gjson.Get(string(respBody), "data.update_time")
+		gomega.Expect(createtime.Int()).To(gomega.SatisfyAll(
+			gomega.BeNumerically(">=", time.Now().Unix()-1),
+			gomega.BeNumerically("<=", time.Now().Unix()+1),
+		))
+
+		gomega.Expect(updatetime.Int()).To(gomega.SatisfyAll(
+			gomega.BeNumerically(">=", time.Now().Unix()-1),
+			gomega.BeNumerically("<=", time.Now().Unix()+1),
+		))
+	})
+
+	table.DescribeTable("test for route with name description",
+		func(tc base.HttpTestCase) {
+			base.RunTestCase(tc)
+		},
+		table.Entry("update the route (r1)", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Path:   "/apisix/admin/routes/r1",
+			Method: http.MethodPut,
+			Body: `{
+					"name": "route1",
+					"uri": "/hello",
+					"name": "new jack",
+					"desc": "new desc",
+					"upstream": {
+						"type": "roundrobin",
+						"nodes": [{
+							"host": "172.16.238.20",
+							"port": 1980,
+							"weight": 1
+						}]
+					}
+				}`,
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			Sleep:        time.Duration(2) * time.Second,
+		}),
+		table.Entry("access the route's uri (r1)", base.HttpTestCase{
+			Object:       base.APISIXExpect(),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        base.SleepTime,
+		}),
+	)
+
+	ginkgo.It("get the updated route information", func() {
+		time.Sleep(time.Duration(100) * time.Millisecond)
+		basepath := base.ManagerAPIHost + "/apisix/admin/routes"
+
+		request, _ := http.NewRequest("GET", basepath+"/r1", nil)
+		request.Header.Add("Authorization", base.GetToken())
+		resp, _ := http.DefaultClient.Do(request)
+		respBody, _ := ioutil.ReadAll(resp.Body)
+		createtime2 := gjson.Get(string(respBody), "data.create_time")
+		updatetime2 := gjson.Get(string(respBody), "data.update_time")
+		//verify the route and compare result
+		gomega.Expect(gjson.Get(string(respBody), "data.name").String()).To(gomega.Equal("new jack"))
+		gomega.Expect(gjson.Get(string(respBody), "data.desc").String()).To(gomega.Equal("new desc"))
+		gomega.Expect(createtime2.String()).To(gomega.Equal(createtime.String()))
+		gomega.Expect(updatetime2.String()).NotTo(gomega.Equal(updatetime.String()))
+	})
+
+	ginkgo.It("delete the route (r1)", func() {
+		base.RunTestCase(base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/routes/r1",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+		})
+	})

Review comment:
       Done :heavy_check_mark: 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org