You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/01/23 11:28:02 UTC
[apisix] branch master updated: test: add grpc-web text format data case (#6179)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 4e0ce48 test: add grpc-web text format data case (#6179)
4e0ce48 is described below
commit 4e0ce487230bd544c565436c0e068f99a8d66e04
Author: 帅进超 <sh...@gmail.com>
AuthorDate: Sun Jan 23 19:27:54 2022 +0800
test: add grpc-web text format data case (#6179)
---
t/plugin/grpc-web.t | 38 +++++++++----
...es_grpc_web_pb.js => routes_grpc_web_bin_pb.js} | 0
...s_grpc_web_pb.js => routes_grpc_web_text_pb.js} | 4 +-
t/plugin/grpc-web/client.js | 62 +++++++++++++---------
4 files changed, 67 insertions(+), 37 deletions(-)
diff --git a/t/plugin/grpc-web.t b/t/plugin/grpc-web.t
index 52e0405..b28e3ad 100644
--- a/t/plugin/grpc-web.t
+++ b/t/plugin/grpc-web.t
@@ -74,65 +74,81 @@ passed
=== TEST 2: Flush all data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js FLUSH
+node ./t/plugin/grpc-web/client.js BIN FLUSH
+node ./t/plugin/grpc-web/client.js TEXT FLUSH
--- response_body
[]
+[]
=== TEST 3: Insert first data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js POST 1 route01 path01
+node ./t/plugin/grpc-web/client.js BIN POST 1 route01 path01
+node ./t/plugin/grpc-web/client.js TEXT POST 1 route01 path01
--- response_body
[["1",{"name":"route01","path":"path01"}]]
+[["1",{"name":"route01","path":"path01"}]]
=== TEST 4: Update data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js PUT 1 route01 hello
+node ./t/plugin/grpc-web/client.js BIN PUT 1 route01 hello
+node ./t/plugin/grpc-web/client.js TEXT PUT 1 route01 hello
--- response_body
[["1",{"name":"route01","path":"hello"}]]
+[["1",{"name":"route01","path":"hello"}]]
=== TEST 5: Insert second data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js POST 2 route02 path02
+node ./t/plugin/grpc-web/client.js BIN POST 2 route02 path02
+node ./t/plugin/grpc-web/client.js TEXT POST 2 route02 path02
--- response_body
[["1",{"name":"route01","path":"hello"}],["2",{"name":"route02","path":"path02"}]]
+[["1",{"name":"route01","path":"hello"}],["2",{"name":"route02","path":"path02"}]]
=== TEST 6: Insert third data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js POST 3 route03 path03
+node ./t/plugin/grpc-web/client.js BIN POST 3 route03 path03
+node ./t/plugin/grpc-web/client.js TEXT POST 3 route03 path03
--- response_body
[["1",{"name":"route01","path":"hello"}],["2",{"name":"route02","path":"path02"}],["3",{"name":"route03","path":"path03"}]]
+[["1",{"name":"route01","path":"hello"}],["2",{"name":"route02","path":"path02"}],["3",{"name":"route03","path":"path03"}]]
=== TEST 7: Delete first data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js DEL 1
+node ./t/plugin/grpc-web/client.js BIN DEL 3
+node ./t/plugin/grpc-web/client.js TEXT DEL 2
--- response_body
-[["2",{"name":"route02","path":"path02"}],["3",{"name":"route03","path":"path03"}]]
+[["1",{"name":"route01","path":"hello"}],["2",{"name":"route02","path":"path02"}]]
+[["1",{"name":"route01","path":"hello"}]]
=== TEST 8: Get second data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js GET 2
+node ./t/plugin/grpc-web/client.js BIN GET 1
+node ./t/plugin/grpc-web/client.js TEXT GET 1
--- response_body
-{"name":"route02","path":"path02"}
+{"name":"route01","path":"hello"}
+{"name":"route01","path":"hello"}
=== TEST 9: Get all data through APISIX gRPC-Web Proxy
--- exec
-node ./t/plugin/grpc-web/client.js all
+node ./t/plugin/grpc-web/client.js BIN all
+node ./t/plugin/grpc-web/client.js TEXT all
--- response_body
-[["2",{"name":"route02","path":"path02"}],["3",{"name":"route03","path":"path03"}]]
+[["1",{"name":"route01","path":"hello"}]]
+[["1",{"name":"route01","path":"hello"}]]
diff --git a/t/plugin/grpc-web/a6/routes_grpc_web_pb.js b/t/plugin/grpc-web/a6/routes_grpc_web_bin_pb.js
similarity index 100%
copy from t/plugin/grpc-web/a6/routes_grpc_web_pb.js
copy to t/plugin/grpc-web/a6/routes_grpc_web_bin_pb.js
diff --git a/t/plugin/grpc-web/a6/routes_grpc_web_pb.js b/t/plugin/grpc-web/a6/routes_grpc_web_text_pb.js
similarity index 99%
rename from t/plugin/grpc-web/a6/routes_grpc_web_pb.js
rename to t/plugin/grpc-web/a6/routes_grpc_web_text_pb.js
index fff570e..725e5fa 100644
--- a/t/plugin/grpc-web/a6/routes_grpc_web_pb.js
+++ b/t/plugin/grpc-web/a6/routes_grpc_web_text_pb.js
@@ -32,7 +32,7 @@ proto.a6 = require('./routes_pb.js');
proto.a6.RouteServiceClient =
function(hostname, credentials, options) {
if (!options) options = {};
- options.format = 'binary';
+ options.format = 'text';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
@@ -58,7 +58,7 @@ proto.a6.RouteServiceClient =
proto.a6.RouteServicePromiseClient =
function(hostname, credentials, options) {
if (!options) options = {};
- options.format = 'binary';
+ options.format = 'text';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
diff --git a/t/plugin/grpc-web/client.js b/t/plugin/grpc-web/client.js
index 7f37ff0..3cbb273 100644
--- a/t/plugin/grpc-web/client.js
+++ b/t/plugin/grpc-web/client.js
@@ -18,7 +18,13 @@
global.XMLHttpRequest = require('xhr2')
const {Empty, Request, Route} = require('./a6/routes_pb')
-const {RouteServiceClient} = require('./a6/routes_grpc_web_pb')
+const RouteServiceBinProtocolClient = require('./a6/routes_grpc_web_bin_pb').RouteServiceClient
+const RouteServiceTextProtocolClient = require('./a6/routes_grpc_web_text_pb').RouteServiceClient
+
+const MODE_TEXT = "TEXT"
+const MODE_BIN = "BIN"
+
+const modes = [MODE_TEXT, MODE_BIN];
const FUNCTION_ALL = "ALL"
const FUNCTION_GET = "GET"
@@ -31,12 +37,14 @@ const functions = [FUNCTION_ALL, FUNCTION_GET, FUNCTION_POST, FUNCTION_PUT, FUNC
class gRPCWebClient {
constructor() {
- this.client = new RouteServiceClient("http://127.0.0.1:1984/grpc", null, null)
+ this.clients = {}
+ this.clients[MODE_BIN] = new RouteServiceBinProtocolClient("http://127.0.0.1:1984/grpc")
+ this.clients[MODE_TEXT] = new RouteServiceTextProtocolClient("http://127.0.0.1:1984/grpc")
};
- flush() {
+ flush(mode) {
let request = new Empty()
- this.client.flushAll(request, {}, function (error, response) {
+ this.clients[mode].flushAll(request, {}, function (error, response) {
if (error) {
console.log(error)
return
@@ -45,9 +53,9 @@ class gRPCWebClient {
});
}
- all() {
+ all(mode) {
let request = new Empty()
- this.client.getAll(request, {}, function (error, response) {
+ this.clients[mode].getAll(request, {}, function (error, response) {
if (error) {
console.log(error)
return
@@ -56,14 +64,14 @@ class gRPCWebClient {
});
}
- get(params) {
+ get(mode, params) {
if (params[0] === null) {
console.log("route ID invalid")
return
}
let request = new Request()
request.setId(params[0])
- this.client.get(request, {}, function (error, response) {
+ this.clients[mode].get(request, {}, function (error, response) {
if (error) {
console.log(error)
return
@@ -72,7 +80,7 @@ class gRPCWebClient {
});
}
- post(params) {
+ post(mode, params) {
if (params[0] === null) {
console.log("route ID invalid")
return
@@ -91,7 +99,7 @@ class gRPCWebClient {
route.setName(params[1])
route.setPath(params[2])
request.setRoute(route)
- this.client.insert(request, {}, function (error, response) {
+ this.clients[mode].insert(request, {}, function (error, response) {
if (error) {
console.log(error)
return
@@ -100,7 +108,7 @@ class gRPCWebClient {
});
}
- put(params) {
+ put(mode, params) {
if (params[0] === null) {
console.log("route ID invalid")
return
@@ -119,7 +127,7 @@ class gRPCWebClient {
route.setName(params[1])
route.setPath(params[2])
request.setRoute(route)
- this.client.update(request, {}, function (error, response) {
+ this.clients[mode].update(request, {}, function (error, response) {
if (error) {
console.log(error)
return
@@ -128,14 +136,14 @@ class gRPCWebClient {
})
}
- del() {
+ del(mode) {
if (params[0] === null) {
console.log("route ID invalid")
return
}
let request = new Request()
request.setId(params[0])
- this.client.remove(request, {}, function (error, response) {
+ this.clients[mode].remove(request, {}, function (error, response) {
if (error) {
console.log(error)
return
@@ -148,31 +156,37 @@ class gRPCWebClient {
const arguments = process.argv.splice(2)
-if (arguments.length === 0) {
- console.log("please input dispatch function, e.g: node client.js insert arg_id arg_name arg_path")
+if (arguments.length < 2) {
+ console.log("please input dispatch function, e.g: node client.js [mode] [action] [params...]")
+ return
+}
+
+const mode = arguments[0].toUpperCase()
+if (!modes.includes(mode)) {
+ console.log("dispatch mode not found")
return
}
-const func = arguments[0].toUpperCase()
+const func = arguments[1].toUpperCase()
if (!functions.includes(func)) {
console.log("dispatch function not found")
return
}
-const params = arguments.splice(1)
+const params = arguments.splice(2)
let grpc = new gRPCWebClient();
if (func === FUNCTION_GET) {
- grpc.get(params)
+ grpc.get(mode, params)
} else if (func === FUNCTION_POST) {
- grpc.post(params)
+ grpc.post(mode, params)
} else if (func === FUNCTION_PUT) {
- grpc.put(params)
+ grpc.put(mode, params)
} else if (func === FUNCTION_DEL) {
- grpc.del(params)
+ grpc.del(mode, params)
} else if (func === FUNCTION_FLUSH) {
- grpc.flush()
+ grpc.flush(mode)
} else {
- grpc.all()
+ grpc.all(mode)
}