-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite e2e test route with plugin orchestration test with ginkgo
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
api/test/e2enew/route/route_with_plugin_orchestration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
) | ||
}) |