testcontainers-scala icon indicating copy to clipboard operation
testcontainers-scala copied to clipboard

support of weaver test framework

Open bwiercinski opened this issue 3 years ago • 2 comments

support of weaver test framework

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

i'm keen to contribute

bwiercinski avatar Nov 09 '21 14:11 bwiercinski

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.

LMnet avatar Nov 10 '21 05:11 LMnet

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()))
}

bplommer avatar Mar 29 '22 09:03 bplommer