You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/07/13 12:31:26 UTC

[incubator-apisix-dashboard] branch master updated: add proxyRewrite test (#319)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 075611b  add proxyRewrite test (#319)
075611b is described below

commit 075611b893c271cb73c37f072a22a922941f7398
Author: kv <gx...@163.com>
AuthorDate: Mon Jul 13 20:31:16 2020 +0800

    add proxyRewrite test (#319)
---
 api/service/route_test.go | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/api/service/route_test.go b/api/service/route_test.go
index 5faacd8..b7fe5da 100644
--- a/api/service/route_test.go
+++ b/api/service/route_test.go
@@ -60,6 +60,41 @@ func TestToApisixRequest_RediretPlugins(t *testing.T) {
 	a.NotEqual(nil, ar.Plugins["redirect"])
 }
 
+func TestToApisixRequest_proxyRewrite(t *testing.T) {
+	nodes := make(map[string]int64)
+	nodes["127.0.0.1:8080"] = 100
+	upstream := &Upstream{
+		UType:   "roundrobin",
+		Nodes:   nodes,
+		Timeout: UpstreamTimeout{15, 15, 15},
+	}
+	to := "/hello"
+	upstreamPath := &UpstreamPath{To: to}
+	rr := &RouteRequest{
+		ID:           "u guess a uuid",
+		Name:         "a special name",
+		Desc:         "any description",
+		Priority:     0,
+		Methods:      []string{"GET"},
+		Uris:         []string{},
+		Hosts:        []string{"www.baidu.com"},
+		Protocols:    []string{"http", "https", "websocket"},
+		Redirect:     &Redirect{HttpToHttps: true, Code: 200, Uri: "/hello"},
+		Vars:         [][]string{},
+		Upstream:     upstream,
+		UpstreamPath: upstreamPath,
+	}
+	ar := ToApisixRequest(rr)
+	a := assert.New(t)
+	var pr ProxyRewrite
+	bytes, _ := json.Marshal(ar.Plugins["proxy-rewrite"])
+	json.Unmarshal(bytes, &pr)
+
+	a.Equal(2, len(ar.Plugins))
+	a.NotEqual(nil, ar.Plugins["redirect"])
+	a.Equal(to, pr.Uri)
+}
+
 func TestToApisixRequest_Vars(t *testing.T) {
 	rr := &RouteRequest{
 		ID:        "u guess a uuid",