我将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测试报告交叉。
我该怎么做?
1条答案
按热度按时间e5nqia271#
结果,我只需要应用这个https://www.testcontainers.org/supported_docker_environment/logging_config/。
并将其更改为抑制信息和调试: