Skip to content

Commit

Permalink
Adds a default printf logger for debugging integration tests and adds…
Browse files Browse the repository at this point in the history
… such to the docs for scraperinttest
  • Loading branch information
hughesjj committed Nov 14, 2024
1 parent 4b322db commit 5876528
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/coreinternal/scraperinttest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
},
// ...
}
)
)
```
6 changes: 6 additions & 0 deletions internal/coreinternal/scraperinttest/scraperint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 5876528

Please sign in to comment.