如何在带有ZIO测试的Testtainers Scala中抑制或重定向(例如,重定向到文件)TestContainer输出?

x759pob2  于 2022-11-09  发布在  Scala
关注(0)|答案(1)|浏览(175)

我将ZIO 2和ZIO测试与普通的测试容器一起使用--Scala。
测试看起来是这样的:

object MongoRepositorySpec extends ZIOSpecDefault:

  object TestLayers:
    val mongoTestcontainer: ZLayer[Any, Throwable, MongoDBContainer] =
      ZLayer.scoped(
        ZIO.acquireRelease {
          ZIO
            .attempt(DockerImageName.parse("mongo:4.0.10"))
            .map(tag => MongoDBContainer.Def(tag))
            .map(_.createContainer())
            .tap(c => ZIO.attemptBlocking(c.start))
        }(container => ZIO.attemptBlocking(container.stop()).catchAll(t => ZIO.debug(s"Cannot stop container: $t")))
      )

    val mongoTestcontainerConfig: URLayer[MongoDBContainer, MongoConfig] = ZLayer.fromZIO(
      for container <- ZIO.service[MongoDBContainer]
      yield MongoConfig("localhost", container.mappedPort(27017), "", "", "test")
    )

  def spec = suite("MongoRepositorySpec")(
    test(s"Find GSM tower with cell id ${storedCellTowerGsm1.cellId}") {
      for
        _ <- MongoInserter.insert(storedCellTowerGsm1)
        cell <- MongoRepository.findBy(StoredCellType.Gsm, storedCellTowerGsm1.cellId, storedCellTowerGsm1.lac).some
      yield assertTrue(cell == storedCellTowerGsm1)
    }
  ).provide(
    mongoTestcontainer,
    mongoTestcontainerConfig,
    ZMongo.mongoDatabase,
    ZMongo.mongoClient,
    MongoRepository.live,
    MongoInserter.containerTests
  )

我想抑制发往系统的容器日志,这些日志与来自ZIO测试的NICE测试报告交叉。
我该怎么做?

e5nqia27

e5nqia271#

结果,我只需要应用这个https://www.testcontainers.org/supported_docker_environment/logging_config/
并将其更改为抑制信息和调试:

<root level="warn">
    <appender-ref ref="STDOUT"/>
</root>

相关问题