-
Notifications
You must be signed in to change notification settings - Fork 542
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
test: add e2e test for config route with service_id or upstream_id #810
Changes from 7 commits
12d7041
210faae
ce62474
fa17529
ed9babb
01df9be
feffc04
b776aa7
2e93ff3
ea8522c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* | ||
* 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 e2e | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestRoute_Invalid_Service_And_Service(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "use service that not exist", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/r1", | ||
Body: `{ | ||
"uri": "/hello_", | ||
"service_id": "not-exists" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusBadRequest, | ||
}, | ||
{ | ||
caseDesc: "use upstream that not exist", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/r1", | ||
Body: `{ | ||
"uri": "/hello_", | ||
"upstream_id": "not-exists" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusBadRequest, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
{ | ||
caseDesc: "create service and upstream together at the same time", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/r1", | ||
Body: `{ | ||
"uri": "/hello_", | ||
"service_id": "not-exists-service", | ||
"upstream_id": "not-exists-upstream" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusBadRequest, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
}, | ||
} | ||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
func TestRoute_Create_Upstream(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "create upstream", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/upstreams/1", | ||
Body: `{ | ||
"nodes": [{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to check nodes, not only one node. |
||
"host": "172.16.238.20", | ||
"port": 1980, | ||
"weight": 1 | ||
}], | ||
"type": "roundrobin" | ||
}`, | ||
nic-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "create route using the upstream just created", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/r1", | ||
Body: `{ | ||
"uri": "/server_port", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we only enabled one node, please use "/hello". for /server_port, it mainly used to test multiple nodes |
||
"upstream_id": "1" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
Sleep: sleepTime, | ||
}, | ||
{ | ||
caseDesc: "hit the route just created", | ||
Object: APISIXExpect(t), | ||
Method: http.MethodGet, | ||
Path: "/server_port", | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "1980", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the response body is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After studying the current test sample and realizing that the same response was used here[1], I wrote this as well. [1] https://github.com/apache/apisix-dashboard/blob/v2.0/api/test/e2e/upstream_test.go#L73 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [1] https://github.com/apache/apisix-dashboard/blob/v2.0/api/test/e2e/upstream_test.go#L73 is not a good example, @nic-chen please create issue and fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
OK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not family with Go test, I'm confused why the response body is only the port number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After studying the current test sample and realizing that the same response was used here[1], I wrote this as well. [1] https://github.com/apache/apisix-dashboard/blob/v2.0/api/test/e2e/upstream_test.go#L73 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
here is the reason: #810 (comment) |
||
Sleep: sleepTime, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
func TestRoute_Create_Service(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "create service", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/services/200", | ||
Body: `{ | ||
"upstream": { | ||
"type": "roundrobin", | ||
"nodes": [{ | ||
"host": "172.16.238.20", | ||
"port": 1980, | ||
"weight": 1 | ||
}] | ||
} | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "create route using the service just created", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/r2", | ||
Body: `{ | ||
"uri": "/hello", | ||
"service_id": "200" | ||
}`, | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
Sleep: sleepTime, | ||
}, | ||
{ | ||
caseDesc: "hit the route just created", | ||
Object: APISIXExpect(t), | ||
Method: http.MethodGet, | ||
Path: "/hello", | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "hello world\n", | ||
Sleep: sleepTime, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
func TestRoute_Delete_Upstream(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "delete route", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/routes/r1", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "remove upstream", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/upstreams/1", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to check whether this route deleted on the data plane |
||
}, | ||
} | ||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} | ||
|
||
func TestRoute_Delete_Service(t *testing.T) { | ||
tests := []HttpTestCase{ | ||
{ | ||
caseDesc: "delete route", | ||
Object: MangerApiExpect(t), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/routes/r2", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
{ | ||
caseDesc: "remove service", | ||
Object: MangerApiExpect(t), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/services/200", | ||
Headers: map[string]string{"Authorization": token}, | ||
ExpectStatus: http.StatusOK, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
testCaseCheck(tc) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only test controller plane(MangerApiExpect) is not enough, we MUST test data plane(APISIXExpect) at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check whether this route is valid on the data plane