How to mock Grpc Client inside GRPC server implementation for integration tests running with Docker

297 Views Asked by At

In order to do E2E integration testing, I am using docker container to spin up the API service.

  datalake_api:
    build:
      context: ../../../
      dockerfile: go.Dockerfile

Inside API service main.go file, I am initialising another client (lets say C) from another package and passing it to the API server.

client := protos.NewS2ControlPlaneApiServiceClient(conn)

s := service.NewDatalakeApiServiceImpl(client, store)
grpcServer := server.NewGrpcServer(
    server.WithReflection(),
    server.WithUnaryServerInterceptors(
        middleware.DataDogMetrics(dd),
        middleware.ErrorsOnlyGrpcZapLogger(zapLogger),
        middleware.RequestBodyLogger(middleware.ErrorsOnlyDecider()),
    ),
    server.WithRegisteredServices(s.Register),
)

Currently the API server in docker container is looking for the client at localhost:38644, but its not available.

I dont want to create separate container(s) for C, because it has its dependencies and I will have to create for all then, so I want to mock it in integration tests. Any idea on how can we mock this client?

0

There are 0 best solutions below