monkeyDluffy6017 commented on code in PR #7639:
URL: https://github.com/apache/apisix/pull/7639#discussion_r944148237


##########
t/plugin/grpc-transcode3.t:
##########
@@ -122,3 +122,447 @@ POST /grpctest
 Content-Type: application/json
 --- response_body chomp
 {"message":"Hello world, name: Joe, age: 1, name: Jake, age: 2"}
+
+
+
+=== TEST 3: set proto (id: 1, get error response from rpc)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/proto/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "content" : "syntax = \"proto3\";
+                      package helloworld;
+                      service Greeter {
+                          rpc GetErrResp (HelloRequest) returns (HelloReply) {}
+                      }
+                      message HelloRequest {
+                          string name = 1;
+                          repeated string items = 2;
+                      }
+                      message HelloReply {
+                          string message = 1;
+                          repeated string items = 2;
+                      }
+                      message ErrorDetail {
+                          int64 code = 1;
+                          string message = 2;
+                          string type = 3;
+                      }"
+                   }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 4: set routes (id: 1, get error response from rpc)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "methods": ["GET", "POST"],
+                    "uri": "/grpctest",
+                    "plugins": {
+                        "grpc-transcode": {
+                            "proto_id": "1",
+                            "service": "helloworld.Greeter",
+                            "method": "GetErrResp"
+                        }
+                    },
+                    "upstream": {
+                        "scheme": "grpc",
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:50051": 1
+                        }
+                    }
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 5: hit route (error response in header)
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin").test
+
+            local code, body, headers = t('/grpctest?name=world',
+                ngx.HTTP_GET
+            )
+
+            ngx.status = code
+
+            ngx.header['grpc-status'] = headers['grpc-status']
+            ngx.header['grpc-message'] = headers['grpc-message']
+            ngx.header['grpc-status-details-bin'] = 
headers['grpc-status-details-bin']
+
+            body = json.encode(body)
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_headers
+grpc-status: 14
+grpc-message: Out of service
+grpc-status-details-bin: 
CA4SDk91dCBvZiBzZXJ2aWNlGlcKKnR5cGUuZ29vZ2xlYXBpcy5jb20vaGVsbG93b3JsZC5FcnJvckRldGFpbBIpCAESHFRoZSBzZXJ2ZXIgaXMgb3V0IG9mIHNlcnZpY2UaB3NlcnZpY2U
+--- response_body_unlike eval
+qr/error/
+--- no_error_log
+[error]
+--- error_code: 503
+
+
+
+=== TEST 6: set routes (id: 1, show error response in body)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "methods": ["GET", "POST"],
+                    "uri": "/grpctest",
+                    "plugins": {
+                        "grpc-transcode": {
+                            "proto_id": "1",
+                            "service": "helloworld.Greeter",
+                            "method": "GetErrResp",
+                            "show_status_in_body": true
+                        }
+                    },
+                    "upstream": {
+                        "scheme": "grpc",
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:50051": 1
+                        }
+                    }
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 7: hit route (show error status in body)
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin").test
+
+            local code, body, headers = t('/grpctest?name=world',
+                ngx.HTTP_GET
+            )
+
+            ngx.status = code
+
+            ngx.header['grpc-status'] = headers['grpc-status']
+            ngx.header['grpc-message'] = headers['grpc-message']
+            ngx.header['grpc-status-details-bin'] = 
headers['grpc-status-details-bin']
+
+            body = json.decode(body)
+            body = json.encode(body)
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_headers
+grpc-status: 14
+grpc-message: Out of service
+grpc-status-details-bin: 
CA4SDk91dCBvZiBzZXJ2aWNlGlcKKnR5cGUuZ29vZ2xlYXBpcy5jb20vaGVsbG93b3JsZC5FcnJvckRldGFpbBIpCAESHFRoZSBzZXJ2ZXIgaXMgb3V0IG9mIHNlcnZpY2UaB3NlcnZpY2U
+--- response_body
+{"error":{"code":14,"details":[{"type_url":"type.googleapis.com/helloworld.ErrorDetail","value":"\b\u0001\u0012\u001cThe
 server is out of service\u001a\u0007service"}],"message":"Out of service"}}
+--- no_error_log
+[error]
+--- error_code: 503
+
+
+
+=== TEST 8: set routes (id: 1, show error details in body)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "methods": ["GET", "POST"],
+                    "uri": "/grpctest",
+                    "plugins": {
+                        "grpc-transcode": {
+                            "proto_id": "1",
+                            "service": "helloworld.Greeter",
+                            "method": "GetErrResp",
+                            "show_status_in_body": true,
+                            "status_detail_type": "helloworld.ErrorDetail"
+                        }
+                    },
+                    "upstream": {
+                        "scheme": "grpc",
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:50051": 1
+                        }
+                    }
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 9: hit route (show error details in body)
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require("toolkit.json")
+            local t = require("lib.test_admin").test
+
+            local code, body, headers = t('/grpctest?name=world',
+                ngx.HTTP_GET
+            )
+
+            ngx.status = code
+
+            ngx.header['grpc-status'] = headers['grpc-status']
+            ngx.header['grpc-message'] = headers['grpc-message']
+            ngx.header['grpc-status-details-bin'] = 
headers['grpc-status-details-bin']
+
+            body = json.decode(body)
+            body = json.encode(body)
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_headers
+grpc-status: 14
+grpc-message: Out of service
+grpc-status-details-bin: 
CA4SDk91dCBvZiBzZXJ2aWNlGlcKKnR5cGUuZ29vZ2xlYXBpcy5jb20vaGVsbG93b3JsZC5FcnJvckRldGFpbBIpCAESHFRoZSBzZXJ2ZXIgaXMgb3V0IG9mIHNlcnZpY2UaB3NlcnZpY2U
+--- response_body
+{"error":{"code":14,"details":[{"code":1,"message":"The server is out of 
service","type":"service"}],"message":"Out of service"}}
+--- no_error_log
+[error]
+--- error_code: 503
+
+
+
+=== TEST 10: set routes (id: 1, show error details in body)

Review Comment:
   They are duplicated, deleted.



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

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to