testcontainers / testcontainers-scala

Docker containers for testing in scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support of weaver test framework

bwiercinski opened this issue · comments

support of weaver test framework

this framework works best when a tested code is based on cats effect.

i'm keen to contribute

Hi @bwiercinski !

We are ready for contributions and could help you with this.

A few points I want you to have in mind:

  1. New API approach (from the current scalatest integration) will be more friendly for the weaver.
  2. It looks like the weaver can share resources across suites. It's a great feature for the testcontainers. Scalatest doesn't have a normal way of sharing containers across suites, which is unfortunate. It would be cool if you could use this feature in your integration layer.

Based on quick experimentation, it looks like the following snippet is all you need - it doesn't even need anything Weaver-specific, just a resource of a running container:

package com.dimafeng.testcontainers

import cats.effect.{Resource, Sync}
import cats.syntax.all._

object ContainerResource {
  def apply[F[_], C <: Container](container: F[C])(implicit F: Sync[F]): Resource[F, C] =
    Resource.make(container.flatTap {
      container =>
        F.blocking(container.start())
    })(c => F.blocking(c.stop()))
}