From 58765282411aef4cf4a5c2f3db1353be61ef2819 Mon Sep 17 00:00:00 2001 From: hughesjj Date: Thu, 14 Nov 2024 14:30:13 -0800 Subject: [PATCH] Adds a default printf logger for debugging integration tests and adds such to the docs for scraperinttest --- .../coreinternal/scraperinttest/README.md | 19 +++++++++++++++++++ .../coreinternal/scraperinttest/scraperint.go | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/internal/coreinternal/scraperinttest/README.md b/internal/coreinternal/scraperinttest/README.md index d51769745847..7d86bf64c3f0 100644 --- a/internal/coreinternal/scraperinttest/README.md +++ b/internal/coreinternal/scraperinttest/README.md @@ -3,3 +3,22 @@ This package is intended to be a temporary workspace for extracting common functionality from scraper integration tests. Once stabilized, this code can likely move to `pdatatest` or its sub-packages `pmetrictest`, etc. + +If you're having issue with your `testcontainers.ContainerRequest` starting up, you can use the provided `PrintfLogConsumer` in a [`LogConsumerCfg`](https://pkg.go.dev/github.com/testcontainers/testcontainers-go#LogConsumerConfig) to display the startup logs + +```golang + scraperinttest.NewIntegrationTest( + // ... + scraperinttest.WithContainerRequest( + testcontainers.ContainerRequest{ + // ... + LogConsumerCfg: &testcontainers.LogConsumerConfig{ + Consumers: []testcontainers.LogConsumer{ + &scraperinttest.PrintfLogConsumer{}, + }, + }, + // ... + } + ) + ) +``` diff --git a/internal/coreinternal/scraperinttest/scraperint.go b/internal/coreinternal/scraperinttest/scraperint.go index 3d650a2c284d..ef166ec46606 100644 --- a/internal/coreinternal/scraperinttest/scraperint.go +++ b/internal/coreinternal/scraperinttest/scraperint.go @@ -314,3 +314,9 @@ func RunScript(script []string) testcontainers.ContainerHook { return errors.New(strings.TrimSpace(errStr)) } } + +type PrintfLogConsumer struct{} + +func (g *PrintfLogConsumer) Accept(l testcontainers.Log) { + fmt.Printf("[Container] %s", string(l.Content)) +}