1

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?

Anshum17
  • 201
  • 3
  • 8
  • 2
    I found a way around by using a `FakeClient` struct instead. `if cfg.UseFakeUploader {s2Client = client.NewFakeS2ControlPlaneApiServiceClient()} ` – Anshum17 Nov 02 '22 at 00:31

0 Answers0