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/11/17 07:06:32 UTC

[GitHub] [apisix-dashboard] EnableAsync commented on a change in pull request #810: test: add e2e test for config route with service_id or upstream_id

EnableAsync commented on a change in pull request #810:
URL: https://github.com/apache/apisix-dashboard/pull/810#discussion_r524924440



##########
File path: api/test/e2e/route_service_upstream_test.go
##########
@@ -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,
+		},
+		{
+			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,
+		},
+	}
+	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": [{
+                    			"host": "172.16.238.20",
+                    			"port": 1980,
+                    			"weight": 1
+                		}],
+                		"type": "roundrobin"
+			}`,
+			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",
+				"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",

Review comment:
       After studying the current test sample and realizing that the same response was used here[1], I wrote this as well.
   Thanks for your review, I read `nginx.conf`[2] and `docker-compose.yaml`[3] and found that this `server.lua`[4] script is used, there is a `server_port` function in the `server.lua` script, so the printout here is port
   
   [1] https://github.com/apache/apisix-dashboard/blob/v2.0/api/test/e2e/upstream_test.go#L73
   [2] https://github.com/apache/apisix-dashboard/blob/v2.0/api/test/docker/upstream.conf#L47
   [3] https://github.com/apache/apisix-dashboard/blob/v2.0/api/test/docker/docker-compose.yaml#L116
   [4] https://github.com/apache/apisix/blob/master/t/lib/server.lua#L59




----------------------------------------------------------------
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