otel4s icon indicating copy to clipboard operation
otel4s copied to clipboard

Add builders for `*Testkit`

Open iRevive opened this issue 2 months ago • 0 comments

The general idea is to make *Testkit entry point more flexible.

In the end, we will have three main entry points:

  1. *Testkit.builder[IO].withXXX(...).withYYY(...).build - creates an instance using customization
  2. *Testkit.inMemory[IO]() - creates an instance using defaults
  3. *Testkit.inMemory[IO](_.withXXX(...)) - a mix of 1st and 2nd option, a bit more ergonomic when you need to apply a few customizations

Questions:

1. Do we need option 3: *Testkit.inMemory[IO](_.withXXX(...))?

It requires a default argument to be resolved properly:

def inMemory[F[_]: Async: LocalContextProvider](
  customize: Builder[F] => Builder[F] = identity[Builder[F]](_)
): Resource[F, MetricsTestkit[F]] =
    customize(builder[F]).build

Two overloaded variants for some reason don't work:

def inMemory[F[_]: Async: LocalContextProvider]: Resource[F, MetricsTestkit[F]] =
  builder[F].build

def inMemory[F[_]: Async: LocalContextProvider](
    customize: Builder[F] => Builder[F]
): Resource[F, MetricsTestkit[F]] =
  customize(builder[F]).build

///

MetricsTestkit.inMemory[IO] // compiles fine
MetricsTestkit.inMemory[IO](_.addMeterProviderCustomizer(null)) // fails with
// missing parameter type for expanded function ((<x$19: error>) => x$19.addMeterProviderCustomizer(null))

iRevive avatar Oct 29 '25 20:10 iRevive