Reputation: 2376
I am using ZIO 2 and ZIO Test with plain testcontainers-scala.
The test looks like this:
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
)
I want to suppress the container logs going to System out which interleave with the nice test reporting from ZIO test.
How do I do that?
Upvotes: 3
Views: 365
Reputation: 2376
Turns out, I just needed to apply this https://www.testcontainers.org/supported_docker_environment/logging_config/.
and change this to suppress info and debug:
<root level="warn">
<appender-ref ref="STDOUT"/>
</root>
Upvotes: 3