gRPC Test Utilities for Golang
Test gRPC service and client like a pro.
Prerequisites
Go >= 1.16
Install
go get github.com/nhatthm/grpcmock
Usage
Invoke a gRPC method
Unary Method
package main
import (
"context"
"time"
"github.com/nhatthm/grpcmock"
"google.golang.org/grpc/test/bufconn"
)
func getItem(l *bufconn.Listener, id int32) (interface{}, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*50)
defer cancel()
out := &Item{}
err := grpcmock.InvokeUnary(ctx, "myservice/GetItem",
&GetItemRequest{Id: id}, out,
grpcmock.WithHeader("Locale", "en-US"),
grpcmock.WithBufConnDialer(l),
grpcmock.WithInsecure(),
)
return out, err
}
Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
Paypal donation
or scan this