This is an automated email from the ASF dual-hosted git repository.

kvn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 45ba000  test: add e2e test for config route with plugin orchestration 
(#913)
45ba000 is described below

commit 45ba0009461136cba31505a73018698d8d5cd7ad
Author: nic-chen <[email protected]>
AuthorDate: Mon Nov 30 20:54:32 2020 +0800

    test: add e2e test for config route with plugin orchestration (#913)
    
    * test: add e2e test for config route with plugin orchestration
    
    * fix: code format
    
    * fix: code format
    
    * fix: typo
    
    * fix: add comment for invalid dag config
    
    * fix: add comment for invalid dag config
    
    * fix: remove Chinese char in code
---
 .../e2e/route_with_plugin_orchestration_test.go    | 113 +++++++
 api/test/testdata/dag-conf.json                    | 331 +++++++++++++++++++++
 api/test/testdata/invalid-dag-conf.json            |  55 ++++
 3 files changed, 499 insertions(+)

diff --git a/api/test/e2e/route_with_plugin_orchestration_test.go 
b/api/test/e2e/route_with_plugin_orchestration_test.go
new file mode 100644
index 0000000..c8aff4b
--- /dev/null
+++ b/api/test/e2e/route_with_plugin_orchestration_test.go
@@ -0,0 +1,113 @@
+/*
+ * 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 (
+       "io/ioutil"
+       "net/http"
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestRoute_With_Plugin_Orchestration(t *testing.T) {
+       bytes, err := ioutil.ReadFile("../testdata/dag-conf.json")
+       assert.Nil(t, err)
+       dagConf := string(bytes)
+
+       // invalid dag config that not specified root node
+       bytes, err = ioutil.ReadFile("../testdata/invalid-dag-conf.json")
+       assert.Nil(t, err)
+       invalidDagConf := string(bytes)
+
+       tests := []HttpTestCase{
+               {
+                       caseDesc:     "make sure the route is not created",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       ExpectStatus: http.StatusNotFound,
+                       ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+               },
+               {
+                       caseDesc:     "create route with invalid dag config",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodPut,
+                       Path:         "/apisix/admin/routes/r1",
+                       Body:         invalidDagConf,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusBadRequest,
+               },
+               {
+                       caseDesc:     "make sure the route created failed",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       ExpectStatus: http.StatusNotFound,
+                       ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+                       Sleep:        sleepTime,
+               },
+               {
+                       caseDesc:     "create route with correct dag config",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodPut,
+                       Path:         "/apisix/admin/routes/r1",
+                       Body:         dagConf,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "verify the route(should be blocked)",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       Query:        "t=root.exe",
+                       ExpectStatus: http.StatusForbidden,
+                       ExpectBody:   `blocked`,
+                       Sleep:        sleepTime,
+               },
+               {
+                       caseDesc:     "verify the route(should not be blocked)",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   `hello world`,
+               },
+               {
+                       caseDesc:     "delete route",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/r1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "hit the route just deleted",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       ExpectStatus: http.StatusNotFound,
+                       ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+                       Sleep:        sleepTime,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc)
+       }
+}
diff --git a/api/test/testdata/dag-conf.json b/api/test/testdata/dag-conf.json
new file mode 100644
index 0000000..e056797
--- /dev/null
+++ b/api/test/testdata/dag-conf.json
@@ -0,0 +1,331 @@
+{
+  "name": "route-with-plugin-orchestration",
+  "uri": "/hello*",
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": [{
+      "host": "172.16.238.20",
+      "port": 1980,
+      "weight": 1
+    }]
+  },
+  "script":{
+    "rule":{
+      "root":"451106f8-560c-43a4-acf2-2a6ed0ea57b8",
+      "451106f8-560c-43a4-acf2-2a6ed0ea57b8":[
+        [
+          "code == 403",
+          "b93d622c-92ef-48b4-b6bb-57e1ce893ee3"
+        ],
+        [
+          "",
+          "988ef5c2-c896-4606-a666-3d4cbe24a731"
+        ]
+      ]
+    },
+    "conf":{
+      "451106f8-560c-43a4-acf2-2a6ed0ea57b8":{
+        "name":"uri-blocker",
+        "conf":{
+          "block_rules":[
+            "root.exe",
+            "root.m+"
+          ],
+          "rejected_code":403
+        }
+      },
+      "988ef5c2-c896-4606-a666-3d4cbe24a731":{
+        "name":"kafka-logger",
+        "conf":{
+          "batch_max_size":1000,
+          "broker_list":{
+
+          },
+          "buffer_duration":60,
+          "inactive_timeout":5,
+          "include_req_body":false,
+          "kafka_topic":"1",
+          "key":"2",
+          "max_retry_count":0,
+          "name":"kafka logger",
+          "retry_delay":1,
+          "timeout":3
+        }
+      },
+      "b93d622c-92ef-48b4-b6bb-57e1ce893ee3":{
+        "name":"fault-injection",
+        "conf":{
+          "abort":{
+            "body":"blocked",
+            "http_status":403
+          },
+          "delay":{
+            "duration":2
+          }
+        }
+      }
+    },
+    "chart":{
+      "hovered":{
+
+      },
+      "links":{
+        "3a110c30-d6f3-40b1-a8ac-b828cfaa2489":{
+          "from":{
+            "nodeId":"3365eca3-4bc8-4769-bab3-1485dfd6a43c",
+            "portId":"port3"
+          },
+          "id":"3a110c30-d6f3-40b1-a8ac-b828cfaa2489",
+          "to":{
+            "nodeId":"b93d622c-92ef-48b4-b6bb-57e1ce893ee3",
+            "portId":"port1"
+          }
+        },
+        "c1958993-c1ef-44b1-bb32-7fc6f34870c2":{
+          "from":{
+            "nodeId":"3365eca3-4bc8-4769-bab3-1485dfd6a43c",
+            "portId":"port2"
+          },
+          "id":"c1958993-c1ef-44b1-bb32-7fc6f34870c2",
+          "to":{
+            "nodeId":"988ef5c2-c896-4606-a666-3d4cbe24a731",
+            "portId":"port1"
+          }
+        },
+        "f9c42bf6-c8aa-4e86-8498-8dfbc5c53c23":{
+          "from":{
+            "nodeId":"451106f8-560c-43a4-acf2-2a6ed0ea57b8",
+            "portId":"port2"
+          },
+          "id":"f9c42bf6-c8aa-4e86-8498-8dfbc5c53c23",
+          "to":{
+            "nodeId":"3365eca3-4bc8-4769-bab3-1485dfd6a43c",
+            "portId":"port1"
+          }
+        }
+      },
+      "nodes":{
+        "3365eca3-4bc8-4769-bab3-1485dfd6a43c":{
+          "id":"3365eca3-4bc8-4769-bab3-1485dfd6a43c",
+          "orientation":0,
+          "ports":{
+            "port1":{
+              "id":"port1",
+              "position":{
+                "x":107,
+                "y":0
+              },
+              "type":"input"
+            },
+            "port2":{
+              "id":"port2",
+              "position":{
+                "x":92,
+                "y":96
+              },
+              "properties":{
+                "value":"no"
+              },
+              "type":"output"
+            },
+            "port3":{
+              "id":"port3",
+              "position":{
+                "x":122,
+                "y":96
+              },
+              "properties":{
+                "value":"yes"
+              },
+              "type":"output"
+            }
+          },
+          "position":{
+            "x":750.2627969928922,
+            "y":301.0370335799397
+          },
+          "properties":{
+            "customData":{
+              "name":"code == 403",
+              "type":1
+            }
+          },
+          "size":{
+            "height":96,
+            "width":214
+          },
+          "type":"conditions"
+        },
+        "451106f8-560c-43a4-acf2-2a6ed0ea57b8":{
+          "id":"451106f8-560c-43a4-acf2-2a6ed0ea57b8",
+          "orientation":0,
+          "ports":{
+            "port1":{
+              "id":"port1",
+              "position":{
+                "x":100,
+                "y":0
+              },
+              "properties":{
+                "custom":"property"
+              },
+              "type":"input"
+            },
+            "port2":{
+              "id":"port2",
+              "position":{
+                "x":100,
+                "y":96
+              },
+              "properties":{
+                "custom":"property"
+              },
+              "type":"output"
+            }
+          },
+          "position":{
+            "x":741.5684544145346,
+            "y":126.75879247285502
+          },
+          "properties":{
+            "customData":{
+              "data":{
+                "block_rules":[
+                  "root.exe",
+                  "root.m+"
+                ],
+                "rejected_code":403
+              },
+              "name":"uri-blocker",
+              "type":0
+            }
+          },
+          "size":{
+            "height":96,
+            "width":201
+          },
+          "type":"uri-blocker"
+        },
+        "988ef5c2-c896-4606-a666-3d4cbe24a731":{
+          "id":"988ef5c2-c896-4606-a666-3d4cbe24a731",
+          "orientation":0,
+          "ports":{
+            "port1":{
+              "id":"port1",
+              "position":{
+                "x":106,
+                "y":0
+              },
+              "properties":{
+                "custom":"property"
+              },
+              "type":"input"
+            },
+            "port2":{
+              "id":"port2",
+              "position":{
+                "x":106,
+                "y":96
+              },
+              "properties":{
+                "custom":"property"
+              },
+              "type":"output"
+            }
+          },
+          "position":{
+            "x":607.9687500000001,
+            "y":471.17788461538447
+          },
+          "properties":{
+            "customData":{
+              "data":{
+                "batch_max_size":1000,
+                "broker_list":{
+
+                },
+                "buffer_duration":60,
+                "inactive_timeout":5,
+                "include_req_body":false,
+                "kafka_topic":"1",
+                "key":"2",
+                "max_retry_count":0,
+                "name":"kafka logger",
+                "retry_delay":1,
+                "timeout":3
+              },
+              "name":"kafka-logger",
+              "type":0
+            }
+          },
+          "size":{
+            "height":96,
+            "width":212
+          },
+          "type":"kafka-logger"
+        },
+        "b93d622c-92ef-48b4-b6bb-57e1ce893ee3":{
+          "id":"b93d622c-92ef-48b4-b6bb-57e1ce893ee3",
+          "orientation":0,
+          "ports":{
+            "port1":{
+              "id":"port1",
+              "position":{
+                "x":110,
+                "y":0
+              },
+              "properties":{
+                "custom":"property"
+              },
+              "type":"input"
+            },
+            "port2":{
+              "id":"port2",
+              "position":{
+                "x":110,
+                "y":96
+              },
+              "properties":{
+                "custom":"property"
+              },
+              "type":"output"
+            }
+          },
+          "position":{
+            "x":988.9074986362261,
+            "y":478.62041800736495
+          },
+          "properties":{
+            "customData":{
+              "data":{
+                "abort":{
+                  "body":"200",
+                  "http_status":300
+                },
+                "delay":{
+                  "duration":500
+                }
+              },
+              "name":"fault-injection",
+              "type":0
+            }
+          },
+          "size":{
+            "height":96,
+            "width":219
+          },
+          "type":"fault-injection"
+        }
+      },
+      "offset":{
+        "x":-376.83,
+        "y":87.98
+      },
+      "scale":0.832,
+      "selected":{
+        "id":"b93d622c-92ef-48b4-b6bb-57e1ce893ee3",
+        "type":"node"
+      }
+    }
+  }
+}
diff --git a/api/test/testdata/invalid-dag-conf.json 
b/api/test/testdata/invalid-dag-conf.json
new file mode 100644
index 0000000..c11916a
--- /dev/null
+++ b/api/test/testdata/invalid-dag-conf.json
@@ -0,0 +1,55 @@
+{
+  "name": "route-with-plugin-orchestration",
+  "uri": "/hello",
+  "upstream": {
+    "type": "roundrobin",
+    "nodes": [{
+      "host": "172.16.238.20",
+      "port": 1980,
+      "weight": 1
+    }]
+  },
+  "script":{
+    "rule":{
+      "11-22-33-44":[
+        [
+          "code == 503",
+          "yy-uu-ii-oo"
+        ],
+        [
+          "",
+          "vv-cc-xx-zz"
+        ]
+      ]
+    },
+    "conf":{
+      "11-22-33-44":{
+        "name": "limit-count",
+        "conf": {
+          "count":2,
+          "time_window":60,
+          "rejected_code":503,
+          "key":"remote_addr"
+        }
+      },
+      "yy-uu-ii-oo":{
+        "name": "response-rewrite",
+        "conf": {
+          "body":"request has been limited",
+          "headers":{
+            "X-limit-status": "limited"
+          }
+        }
+      },
+      "vv-cc-xx-zz":{
+        "name": "response-rewrite",
+        "conf": {
+          "body":"normal request",
+          "headers":{
+            "X-limit-status": "normal"
+          }
+        }
+      }
+    }
+  }
+}

Reply via email to