Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qawatake/grpcmock
grpcmock provides a mock gRPC server from a generated gRPC client code
https://github.com/qawatake/grpcmock
go golang
Last synced: about 2 months ago
JSON representation
grpcmock provides a mock gRPC server from a generated gRPC client code
- Host: GitHub
- URL: https://github.com/qawatake/grpcmock
- Owner: qawatake
- License: mit
- Created: 2024-02-18T04:11:14.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-10-07T23:20:21.000Z (3 months ago)
- Last Synced: 2024-10-14T04:21:53.727Z (2 months ago)
- Topics: go, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/qawatake/grpcmock
- Size: 73.2 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grpcmock
[![Go Reference](https://pkg.go.dev/badge/github.com/qawatake/grpcmock.svg)](https://pkg.go.dev/github.com/qawatake/grpcmock)
[![test](https://github.com/qawatake/grpcmock/actions/workflows/test.yaml/badge.svg)](https://github.com/qawatake/grpcmock/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/qawatake/grpcmock/graph/badge.svg?token=iBMN98cHlc)](https://codecov.io/gh/qawatake/grpcmock)grpcmock provides a mock gRPC server from a generated gRPC client code.
This package currently supports unary RPCs only.
```go
func TestClient(t *testing.T) {
ts := grpcmock.NewServer(t)
conn := ts.ClientConn()
client := hello.NewGrpcTestServiceClient(conn)// Register a mock response.
helloRPC := grpcmock.Register(ts, "/hello.GrpcTestService/Hello", hello.GrpcTestServiceClient.Hello).
Response(&hello.HelloResponse{
Message: "Hello, world!",
})
ts.Start()ctx := context.Background()
res, _ := client.Hello(ctx, &hello.HelloRequest{Name: "qawatake"})if res.Message != "Hello, world!" {
t.Errorf("unexpected response: %s", res.Message)
}
{
// Retrieve the request(s)
got := helloRPC.Requests()[0].Body
if got.Name != "qawatake" {
t.Errorf("unexpected request: %v", got)
}
}
}
```## References
- [k1LoW/grpcstub]: provides a stub gRPC server from protobuf files (not from generated gRPC client code)
[k1LoW/grpcstub]: https://github.com/k1LoW/grpcstub