Skip to content

Commit

Permalink
fix: remove configuration reading from logger initialization
Browse files Browse the repository at this point in the history
Due to the addition of a new init function for the logger initialization
and Ryuk disable message, the environment variables were reading as an
init function side effect. This caused variables set on the code using
the `os` package does not read property.

It removes the reading for the environment variables from the logger
initialization, and prints the message in a more appropriate location.
  • Loading branch information
henrybarreto committed Jul 19, 2024
1 parent 70b90cc commit 9005c60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 11 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ type TestcontainersConfig struct {
// of the TestcontainersConfig struct
func ReadConfig() TestcontainersConfig {
cfg := config.Read()

if cfg.RyukDisabled {
ryukDisabledMessage := `
**********************************************************************************************
Ryuk has been disabled for the current execution. This can cause unexpected behavior in your environment.
More on this: https://golang.testcontainers.org/features/garbage_collector/
**********************************************************************************************`

Logger.Printf(ryukDisabledMessage)
}

return TestcontainersConfig{
Host: cfg.Host,
TLSVerify: cfg.TLSVerify,
Expand Down
11 changes: 0 additions & 11 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"testing"

"github.com/docker/docker/client"

"github.com/testcontainers/testcontainers-go/internal/config"
)

// Logger is the default log instance
Expand All @@ -27,15 +25,6 @@ func init() {
if !verbose {
Logger = &noopLogger{}
}

if config.Read().RyukDisabled {
ryukDisabledMessage := `
**********************************************************************************************
Ryuk has been disabled for the current execution. This can cause unexpected behavior in your environment.
More on this: https://golang.testcontainers.org/features/garbage_collector/
**********************************************************************************************`
Logger.Printf(ryukDisabledMessage)
}
}

// Validate our types implement the required interfaces.
Expand Down

0 comments on commit 9005c60

Please # to comment.