Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sample app for grpc client mocking #122

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions grpc-http-sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# gRPC & HTTP Server Setup with Keploy

This guide explains how to set up and run the gRPC and HTTP servers using Keploy to capture and test the HTTP calls.
Here support grpc client (Unary rpc) has been showed, where keploy is recording incoming http calls and outgoing grpc calls.

## Steps to Run

### 1. Start the gRPC Server

Open a terminal and navigate to the gRPC server directory:

```bash
cd grpc/grpc-server
```

Run the gRPC server:

```bash
go run server.go
```

### 2. Start the HTTP Server in Record Mode

Open another terminal and navigate to the HTTP server directory:

```bash
cd http
```

Build the HTTP server:

```bash
go build -o httpserver
```

Run the HTTP server in record mode to capture the incoming HTTP calls and outgoing gRPC client calls:

```bash
keploy record -c "httpserver"
Sarthak160 marked this conversation as resolved.
Show resolved Hide resolved
```

Make a curl request to the http server :
```bash
curl "http://localhost:8080/hello?name=Jack"
```

### 3. Run the HTTP Server in Test Mode

After recording, run the HTTP server in test mode to replay the captured calls:

```bash
keploy test -c "httpserver"
```

---
15 changes: 15 additions & 0 deletions grpc-http-sample/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/Sarthak160/grpc-http-sample

go 1.22.1

require (
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
)

require (
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
)
14 changes: 14 additions & 0 deletions grpc-http-sample/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
17 changes: 17 additions & 0 deletions grpc-http-sample/grpc/example.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

package example;

option go_package = "grpc-server/example;example"; // <- This line is important

service ExampleService {
rpc SayHello (HelloRequest) returns (HelloResponse);
}

message HelloRequest {
string name = 1;
}

message HelloResponse {
string message = 1;
}
182 changes: 182 additions & 0 deletions grpc-http-sample/grpc/grpc-server/example/example.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading