forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WithLogger ContainerCustomizer support (testcontainers#2259)
* feat: WithLogger ContainerCustomizer support Add support to use WithLogger as a ContainerCustomizer so that callers have an easy way to configure the logger of a container. Add tests for WithLogger. Validate Logger and LoggerOption implement the required interfaces. * chore: add note about order Add a note about WithLogger being used before other functions so it can capture any logging they may generate. Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com> --------- Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
- Loading branch information
1 parent
8838003
commit c474bcd
Showing
3 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package testcontainers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWithLogger(t *testing.T) { | ||
logger := TestLogger(t) | ||
logOpt := WithLogger(logger) | ||
t.Run("container", func(t *testing.T) { | ||
var req GenericContainerRequest | ||
logOpt.Customize(&req) | ||
require.Equal(t, logger, req.Logger) | ||
}) | ||
|
||
t.Run("provider", func(t *testing.T) { | ||
var opts GenericProviderOptions | ||
logOpt.ApplyGenericTo(&opts) | ||
require.Equal(t, logger, opts.Logger) | ||
}) | ||
|
||
t.Run("docker", func(t *testing.T) { | ||
opts := &DockerProviderOptions{ | ||
GenericProviderOptions: &GenericProviderOptions{}, | ||
} | ||
logOpt.ApplyDockerTo(opts) | ||
require.Equal(t, logger, opts.Logger) | ||
}) | ||
} |