Skip to content

Commit

Permalink
feat: rewrite e2e test route with plugin orchestration test with ginkgo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaycean committed Mar 24, 2021
1 parent 576ba1d commit aa3e6cd
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/test/e2enew/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions api/test/e2enew/route/route_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
111 changes: 111 additions & 0 deletions api/test/e2enew/route/route_with_plugin_orchestration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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"

"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
"github.com/onsi/gomega"

"github.com/apisix/manager-api/test/e2enew/base"
)

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")
ginkgo.It("panics if readfile invalid-dag-conf.json error", func() {
gomega.Expect(err).To(gomega.BeNil())
})
invalidDagConf := string(bytes)

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"}`,
}),
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": base.GetToken()},
ExpectStatus: http.StatusBadRequest,
}),
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: 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": base.GetToken()},
ExpectStatus: http.StatusOK,
}),
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: 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`,
}),
table.Entry("delete route", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodDelete,
Path: "/apisix/admin/routes/r1",
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}),
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: base.SleepTime,
}),
)
})

0 comments on commit aa3e6cd

Please sign in to comment.