diff --git a/docker_mounts.go b/docker_mounts.go index 5d654b9a60..d3d2b1525f 100644 --- a/docker_mounts.go +++ b/docker_mounts.go @@ -173,7 +173,7 @@ func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount { case ImageMounter: containerMount.ImageOptions = typedMounter.ImageOptions() case BindMounter: - log.Printf("Mount type %s is not supported by Testcontainers for Go", m.Source.Type()) + log.Printf("Mount type %v is not supported by Testcontainers for Go", m.Source.Type()) default: // The provided source type has no custom options } diff --git a/docker_mounts_test.go b/docker_mounts_test.go new file mode 100644 index 0000000000..8a0fda0a50 --- /dev/null +++ b/docker_mounts_test.go @@ -0,0 +1,45 @@ +package testcontainers + +import ( + "fmt" + "strings" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/testcontainers/testcontainers-go/log" +) + +type captureLogger struct { + b *strings.Builder +} + +func (c captureLogger) Printf(format string, v ...any) { + fmt.Fprintf(c.b, format, v...) +} + +func TestMapToDockerMountsBindDiagnosticFormat(t *testing.T) { + // serial: mutates package log.Default() + + // MountType is a defined uint with no String method; the string verb yields a fmt error marker. + badVerb := "%" + "s" + require.Contains(t, fmt.Sprintf(badVerb, MountTypeBind), "%!s(") + require.Equal(t, "0", fmt.Sprintf("%v", MountTypeBind)) + + var buf strings.Builder + prev := log.Default() + log.SetDefault(captureLogger{b: &buf}) + t.Cleanup(func() { log.SetDefault(prev) }) + + mounts := ContainerMounts{ + { + Source: DockerBindMountSource{HostPath: "/host/path"}, + Target: "/container/path", + }, + } + _ = mounts.PrepareMounts() + + msg := buf.String() + require.NotContains(t, msg, "%!s(") + require.Contains(t, msg, "Mount type 0 is not supported by Testcontainers for Go") +}