Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
45 changes: 45 additions & 0 deletions docker_mounts_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
Loading