package health_test import ( "context" "testing" "github.com/fiskerinc/cloud-services/pkg/health" "github.com/fiskerinc/cloud-services/pkg/testhelper" "github.com/pkg/errors" ) func TestMongoDBCheck(t *testing.T) { mock := MockMongoDB{} fn := func() (health.MongoConnCheckInterface, error) { return &mock, nil } check := health.NewMongoDBCheck(fn) err := check(context.Background()) testhelper.NoError(t, "No error", err) mock.Error = errors.New("ping error") err = check(context.Background()) testhelper.Error(t, "Ping error", err) } type MockMongoDB struct { Error error } func (m *MockMongoDB) Ping(ctx context.Context) error { return m.Error }