You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/10/30 06:11:55 UTC

[GitHub] [apisix-dashboard] moonming commented on a change in pull request #612: test: add e2e test for field hosts in `route` api

moonming commented on a change in pull request #612:
URL: https://github.com/apache/apisix-dashboard/pull/612#discussion_r514890091



##########
File path: api/test/e2e/route_test.go
##########
@@ -0,0 +1,164 @@
+/*
+ * 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"
+	"time"
+)
+
+func TestRoute_Host(t *testing.T) {
+
+	//create route use hosts
+    MangerApiExpect(t).PUT("/apisix/admin/routes/r1").WithText(`{
+        "uri": "/hello_",
+        "hosts": ["foo.com", "*.bar.com"],
+        "upstream": {
+            "nodes": {
+                "172.16.238.120:1980": 1
+            },
+            "type": "roundrobin"
+        }
+    }`).
+	    WithHeader("Authorization", accessToken).
+	    Expect().
+	    Status(http.StatusOK)
+
+	//sleep
+	time.Sleep(time.Duration(100) * time.Millisecond)
+
+	//hit route -- not found
+	APISIXExpect(t).GET("/not_found").
+		Expect().
+		Status(http.StatusNotFound)
+
+	//hit route -- not found, wrong host
+	APISIXExpect(t).GET("/hello_").
+		WithHeader("Host", "not_found.com").
+		Expect().
+		Status(http.StatusNotFound)
+
+	//hit route - ok
+	APISIXExpect(t).GET("/hello_").
+		WithHeader("Host", "foo.com").
+		Expect().
+		Status(http.StatusOK)
+
+	//create route  -- invalid hosts
+	MangerApiExpect(t).PUT("/apisix/admin/routes/r2").WithText(`{
+        "uri": "/hello_",
+        "hosts": ["$%$foo.com", "*.bar.com"],
+        "upstream": {
+            "nodes": {
+                "172.16.238.120:1980": 1
+            },
+            "type": "roundrobin"
+        }
+    }`).

Review comment:
       > We may use some tools to lint those files automatically, cc @nic-chen
   > 
   > [1] https://golangci-lint.run/
   
   we can add to this linter to CI too.




----------------------------------------------------------------
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:
users@infra.apache.org