A sample application that features a gRPC server handling CRUD operations with unary and streaming RPCs, and a client web server translating HTTP requests into gRPC calls.
git clone https://github.com/keploy/samples-go.git && cd samples-go/go-grpc
go mod downloadKeploy can be used on Linux, Windows and MacOS through Docker.
Note: To run Keploy on MacOS through Docker the version must be
4.25.2or above.
go build -o grpc-server .
go build -o grpc-client ./clientOnce we have our binary file ready,this command will start the recording of API calls:
sudo -E keploy record -c "bash -c './grpc-server & ./grpc-client'"To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl
- For health checks :
curl http://localhost:8080/health- POST request calling unary RPCs
curl -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{
"name": "test-user",
"email": "[email protected]",
"age": 20
}'- GET request calling unary RPCs
curl -X GET http://localhost:8080/users- PUT request calling unary RPCs
curl -X PUT http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{
"id": 1,
"name": "test-user-updated",
"email": "[email protected]",
"age": 20
}'- DELETE request calling unary RPCs
curl -X DELETE http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{
"id": 1
}'NOTE: Currently, streaming RPC support is not integrated with Keploy's gRPC parser. Therefore, the following API calls may not work as expected with Keploy:
- POST request calling streaming RPCs
curl -X POST http://localhost:8080/users/stream \
-H "Content-Type: application/json" \
-d '[
{
"name": "test1",
"email": "[email protected]",
"age": 20
},
{
"name": "test2",
"email": "[email protected]",
"age": 20
},
{
"name": "test3",
"email": "[email protected]",
"age": 20
}
]'- GET request calling streaming RPCs
curl -X GET http://localhost:8080/users/stream- PUT request calling streaming RPCs
curl -X PUT http://localhost:8080/users/stream \
-H "Content-Type: application/json" \
-d '[
{
"id": 2,
"name": "test1-updated",
"email": "[email protected]",
"age": 20
},
{
"id": 4,
"name": "test3-updated",
"email": "[email protected]",
"age": 20
}
]'- DELETE request calling streaming RPCs
curl -X DELETE http://localhost:8080/users/stream \
-H "Content-Type: application/json" \
-d '[
{
"id": 2
},
{
"id": 3
}
]'Now all these API calls were captured as a testcase and should be visible on the Keploy CLI. You should be seeing an app named keploy folder with the test cases we just captured and data mocks created.
Now that we have our testcase captured, run the test file.
sudo -E keploy test -c "bash -c './grpc-server & ./grpc-client'"We will get output something like this:
Go to the Keploy log to get deeper insights on what testcases ran, what failed.
For gRPC server:
docker build -t grpc-server:1.0 -f Dockerfile.grpcserver .For gRPC client:
docker build -t grpc-client:1.0 -f Dockerfile.grpcclient .Since, we are on the docker container the gRPC Server URL will be
grpc-server:50051. This needs to be updated on the on line 25 inclient/client.gofile
docker run -d --name grpc-server -p 50051:50051 --network keploy-network grpc-server:1.0Once we have our docker image ready,this command will start the recording of API calls:
keploy record -c "docker run -p 8080:8080 --name grpcApp --network keploy-network grpc-client:1.0"To genereate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl
We can generate the test cases by following a similar process to the one used when running Keploy on a local machine.
Now all the API calls were captured as a testcase and should be visible on the Keploy CLI. You should be seeing an app named keploy folder with the test cases we just captured and data mocks created.
Now that we have our test case captured, run the test file (assuming the gRPC server container is still running).
keploy test -c "docker run -p 8080:8080 --name grpcApp --network keploy-network grpc-client:1.0" --buildDelay 15We will get output something like this:
Go to the Keploy log to get deeper insights on what testcases ran, what failed.



