starsz commented on a change in pull request #1218:
URL: https://github.com/apache/apisix-dashboard/pull/1218#discussion_r553711830
##########
File path: api/test/e2e/global_rule_test.go
##########
@@ -282,3 +288,108 @@ func TestGlobalRule(t *testing.T) {
testCaseCheck(tc, t)
}
}
+
+func TestGlobalRule_with_createtime_updatetime(t *testing.T) {
+ tests := []HttpTestCase{
+ {
+ Desc: "create global rule",
+ Object: ManagerApiExpect(t),
+ Path: "/apisix/admin/global_rules/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules":
["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
Review comment:
Style: the format looks not very good.
##########
File path: api/test/e2e/global_rule_test.go
##########
@@ -282,3 +288,108 @@ func TestGlobalRule(t *testing.T) {
testCaseCheck(tc, t)
}
}
+
+func TestGlobalRule_with_createtime_updatetime(t *testing.T) {
+ tests := []HttpTestCase{
+ {
+ Desc: "create global rule",
+ Object: ManagerApiExpect(t),
+ Path: "/apisix/admin/global_rules/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules":
["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+ }
+
+ for _, tc := range tests {
+ testCaseCheck(tc, t)
+ }
+
+ basepath := "http://127.0.0.1:9000/apisix/admin/global_rules/1"
+ time.Sleep(time.Duration(1) * time.Second)
+
+ // get the global_rule, save createtime and updatetime
+ request, _ := http.NewRequest("GET", basepath, nil)
+ request.Header.Add("Authorization", token)
+ resp, err := http.DefaultClient.Do(request)
+ if err != nil {
+ fmt.Printf("server not responding %s", err.Error())
+ }
+ defer resp.Body.Close()
+ respBody, _ := ioutil.ReadAll(resp.Body)
+ createtime := gjson.Get(string(respBody), "data.create_time")
+ updatetime := gjson.Get(string(respBody), "data.update_time")
+
+ // wait 1 second so the update_time should be different
+ time.Sleep(time.Duration(1) * time.Second)
+
+ tests = []HttpTestCase{
+ {
+ Desc: "update the global rule",
+ Object: ManagerApiExpect(t),
+ Path: "/apisix/admin/global_rules/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.1"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)",
"(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+ }
+
+ for _, tc := range tests {
+ testCaseCheck(tc, t)
+ }
+
+ // get the global rule
+ time.Sleep(time.Duration(1) * time.Second)
+ request, _ = http.NewRequest("GET", basepath, nil)
+ request.Header.Add("Authorization", token)
+ resp, _ = http.DefaultClient.Do(request)
Review comment:
Why not keep the same as before? Check the err and close the resp.Body
##########
File path: api/test/e2e/global_rule_test.go
##########
@@ -282,3 +288,108 @@ func TestGlobalRule(t *testing.T) {
testCaseCheck(tc, t)
}
}
+
+func TestGlobalRule_with_createtime_updatetime(t *testing.T) {
+ tests := []HttpTestCase{
+ {
+ Desc: "create global rule",
+ Object: ManagerApiExpect(t),
+ Path: "/apisix/admin/global_rules/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.0"
+ }
+ },
+ "uri-blocker": {
+ "block_rules":
["select.+(from|limit)", "(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+ }
+
+ for _, tc := range tests {
+ testCaseCheck(tc, t)
+ }
+
+ basepath := "http://127.0.0.1:9000/apisix/admin/global_rules/1"
+ time.Sleep(time.Duration(1) * time.Second)
+
+ // get the global_rule, save createtime and updatetime
+ request, _ := http.NewRequest("GET", basepath, nil)
+ request.Header.Add("Authorization", token)
+ resp, err := http.DefaultClient.Do(request)
+ if err != nil {
+ fmt.Printf("server not responding %s", err.Error())
+ }
+ defer resp.Body.Close()
+ respBody, _ := ioutil.ReadAll(resp.Body)
+ createtime := gjson.Get(string(respBody), "data.create_time")
+ updatetime := gjson.Get(string(respBody), "data.update_time")
+
+ // wait 1 second so the update_time should be different
+ time.Sleep(time.Duration(1) * time.Second)
+
+ tests = []HttpTestCase{
+ {
+ Desc: "update the global rule",
+ Object: ManagerApiExpect(t),
+ Path: "/apisix/admin/global_rules/1",
+ Method: http.MethodPut,
+ Body: `{
+ "plugins": {
+ "response-rewrite": {
+ "headers": {
+ "X-VERSION":"1.1"
+ }
+ },
+ "uri-blocker": {
+ "block_rules": ["select.+(from|limit)",
"(?:(union(.*?)select))"]
+ }
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
Review comment:
The sleepTime stands for sleep before request. You can check it in
base.go.
I think there is no need to sleep for you had sleep 1s before.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]