如何使用ZIO测试在Testcontainers Scala中抑制或重定向(例如重定向到文件)Testcontainer



我使用的是带有普通测试容器scala的ZIO 2和ZIO Test。

测试如下:

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
)

我想抑制进入System out的容器日志,这些日志与ZIO测试的漂亮测试报告交织在一起。

我该怎么做?

事实证明,我只需要应用https://www.testcontainers.org/supported_docker_environment/logging_config/.

并将其更改为抑制信息和调试:

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

相关内容

  • 没有找到相关文章

最新更新