Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite e2e test route with plugin orchestration test with ginkgo #1663

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases here only check the admin API, but not concerned about the data use in DP, it's not a closed loop, we may request DP to verify DP's behaviors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
}),
)
})