I need to write a unit test for a function, which in its source code calls a gRPC method of a different gRPC service. My test results in a panic error because that gRPC service is not running on my machine. I want to create a dummy service in my test and that service must serve the method calling inside the source code. How do I do that?
Edit: Details Source function:
func (s *mainType) MainGenerateBearerToken(inputs...)(output) {
response, err := s.Subtype.SubGenerateBearerToken(context, authnPass, ttl)
if err != nil {
return nil, err
}
return &models.OCITokenResponse{Token: response.Token, ExpiresIn: ttl}, nil
}
func(cl *Subtype) SubGenerateBearerToken(context,authnPass, ttl) (*BearerTokenResponse, error) {
resp,err := pb.NewGrpcClient(cl.Conn).GetBearerToken_grpc(ctx, &pb.GetBearerTokenRequest{AuthnToken, BearerTtlValue:ttlNum)
return &BearerTokenResponse{Token}, err
}
I'm writing test for the MainGenerateBearerToken() function, which calls SubGenerateBearerToken(), inside which the grpc method is called.