Recently, we are using Golang to implement microservices, and the communication interface is gRPC. In addition to writing client-side tests in third-party languages supported by gRPC, are there any good tools to verify the interface implemented by gRPC? This year, we saw that Postman announced that it started to support gRPC, so I believe that you are not too unfamiliar with Postman tool, after all, we rely on this tool to test Websocket or RESTful API. This article not only introduces Postman, but also a set of CLI tools grpcurl and a set of GUI tools grpcui is also not bad to use, the latter two sets are developed by the same company FullStory out of the project, the following to introduce one by one.
Testing gRPC service
I have written a test example version, the gRPC definition proto file can be viewed from here.
|
|
grpcurl
I believe we have all used the powerful curl tool, and grpcurl can be thought of as a gRPC version of curl. The installation is very simple, you can find the OS version you want on the Relase page, or if you are a Go developer you can install it via go install.
|
|
MacOS environment can be installed via Homebrew.
|
|
Or you can run it through Docker.
First set up the test environment, then you can test the 8080 port on the local side.
Since there is no SSL certificate on the local side, please add the -plaintext
parameter to use it, the detailed parameters can be checked by -h
, and then type the first test interface.
The results obtained are as follows.
If you have added Health Check to your service, you can use the following command directly.
The results obtained are as follows.
If the service has support for Server Streaming RPC, it is also the same usage.
You can see that Server responds with two messages.
grpcui
In addition to the above grpcurl, the same team has also released grpcui, a gRPC testing tool with a Web UI. grpcui is installed in the same way as grpcurl, so there is no need to explain it here. grpcui also supports all RPC functions, including streaming, etc. The GUI console can be started with the following command line.
|
|
This page has already helped to prepare the Service and the Method that can be used. You don’t need to know which Method is provided by any service, it’s very convenient, and the Request Data on the screen will change when you select different Service and Method.
After filling out the Request Form and switching to Raw Request (JSON), you can see the JSON Format data.
After clicking invoke, you can see the following result.
The results of testing Streaming are as follows.
Postman
I believe you are still most familiar with Postman, testing any service can not be separated from this tool, but also very happy to see the support of gRPC Beta version in January this year, open the software, press the upper left corner of New you can see the following interface, select gRPC Request.
The API on the left can write the proto data of all the services into it.
Then you can select it by New Request and run invoke.
The results of testing Streaming are as follows.
Thoughts
The grpcurl CLI tool can be used in Linux environments where there is basically no desktop, so it is recommended. However, Postman needs to write the proto data manually before it can be tested. So I strongly recommend using grpcui to read the proto information directly and dynamically, and turn the information into Request Form to reduce the time of querying data attributes.
Reference
https://blog.wu-boy.com/2022/08/three-grpc-testing-tool/