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

refactor: migrate route tests to e2enew #2411

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
95 changes: 95 additions & 0 deletions api/test/e2enew/route/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,101 @@ var _ = ginkgo.Describe("Route", func() {
}),
)

table.DescribeTable("update routes with hosts",
bzp2010 marked this conversation as resolved.
Show resolved Hide resolved
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
table.Entry("hit route that not exist", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Host": "foo.com"},
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
}),
table.Entry("create route with host foo.com", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: `{
"name": "route1",
"uri": "/hello",
"methods": ["GET"],
"hosts": ["foo.com"],
"upstream": {
"type": "roundrobin",
"nodes": [{
"host": "` + base.UpstreamIp + `",
"port": 1980,
"weight": 1
}]
}
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: []string{"\"id\":\"r1\"", "\"hosts\":[\"foo.com\"]"},
}),
table.Entry("hit the route just create", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Host": "foo.com"},
ExpectStatus: http.StatusOK,
Sleep: base.SleepTime,
}),
table.Entry("update route with host bar.com", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: `{
"name": "route1",
"uri": "/hello",
"hosts": ["bar.com"],
"upstream": {
"nodes": {
"` + base.UpstreamIp + `:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: []string{"\"id\":\"r1\"", "\"hosts\":[\"bar.com\"]"},
}),
table.Entry("hit the route with host foo.com", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Host": "foo.com"},
ExpectStatus: http.StatusNotFound,
Sleep: base.SleepTime,
}),
table.Entry("hit the route just updated", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Host": "bar.com"},
ExpectStatus: http.StatusOK,
ExpectBody: "hello world\n",
}),
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",
Headers: map[string]string{"Host": "bar.com"},
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
Sleep: base.SleepTime,
}),
)

table.DescribeTable("test route with empty array",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
Expand Down
146 changes: 146 additions & 0 deletions api/test/e2enew/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,150 @@ var _ = ginkgo.Describe("Route", func() {
Sleep: base.SleepTime,
}),
)

table.DescribeTable("test route patch",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
table.Entry("make sure the route not exists", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
}),
table.Entry("create route", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: `{
"name": "route1",
"uri": "/hello",
"upstream": {
"nodes": {
"` + base.UpstreamIp + `:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}),
table.Entry("hit the route just created", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusOK,
ExpectBody: "hello world",
Sleep: base.SleepTime,
}),
table.Entry("route patch for update status(route offline)", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPatch,
Path: "/apisix/admin/routes/r1",
Body: `{"status":0}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
}),
table.Entry("make sure the route has been offline", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
Sleep: base.SleepTime,
}),
table.Entry("route patch for update status (route online)", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPatch,
Path: "/apisix/admin/routes/r1/status",
Body: "1",
Headers: map[string]string{
"Authorization": base.GetToken(),
"Content-Type": "text/plain",
},
ExpectStatus: http.StatusOK,
}),
table.Entry("make sure the route has been online", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello",
ExpectStatus: http.StatusOK,
ExpectBody: "hello world",
Sleep: base.SleepTime,
}),
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\"}\n",
Sleep: base.SleepTime,
}),
)

table.DescribeTable("test route create via POST",
func(tc base.HttpTestCase) {
base.RunTestCase(tc)
},
table.Entry("hit route that not exist", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello_",
Headers: map[string]string{"Host": "foo.com"},
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
}),
table.Entry("create route via HTTP POST", base.HttpTestCase{
Object: base.ManagerApiExpect(),
Method: http.MethodPost,
Path: "/apisix/admin/routes",
Body: `{
"id": "r1",
"name": "route1",
"uri": "/hello_",
"hosts": ["foo.com", "*.bar.com"],
"upstream": {
"nodes": {
"` + base.UpstreamIp + `:1980": 1
},
"type": "roundrobin"
}
}`,
Headers: map[string]string{"Authorization": base.GetToken()},
ExpectStatus: http.StatusOK,
ExpectBody: "\"id\":\"r1\"",
}),
table.Entry("hit the route just created", base.HttpTestCase{
Object: base.APISIXExpect(),
Method: http.MethodGet,
Path: "/hello_",
Headers: map[string]string{"Host": "foo.com"},
ExpectStatus: http.StatusOK,
ExpectBody: "hello world\n",
}),
table.Entry("delete the route just created", 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_",
Headers: map[string]string{"Host": "bar.com"},
ExpectStatus: http.StatusNotFound,
ExpectBody: "{\"error_msg\":\"404 Route Not Found\"}\n",
Sleep: base.SleepTime,
}),
)
})