diff --git a/internal/testutils/logger.go b/internal/testutils/logger.go new file mode 100644 index 0000000000..3207495421 --- /dev/null +++ b/internal/testutils/logger.go @@ -0,0 +1,10 @@ +package testutils + +import "testing" + +// Logger is used to log non-fatal messages during tests. +type Logger interface { + Logf(format string, args ...any) +} + +var _ Logger = (*testing.T)(nil) diff --git a/internal/testutils/netnsutils/context.go b/internal/testutils/netnsutils/context.go index 46537321b4..a493da0e82 100644 --- a/internal/testutils/netnsutils/context.go +++ b/internal/testutils/netnsutils/context.go @@ -1,13 +1,8 @@ package netnsutils -import "testing" - -// Logger is used to log non-fatal messages during tests. -type Logger interface { - Logf(format string, args ...any) -} - -var _ Logger = (*testing.T)(nil) +import ( + "testing" +) // SetupTestOSContext joins the current goroutine to a new network namespace, // and returns its associated teardown function. diff --git a/internal/testutils/netnsutils/context_unix.go b/internal/testutils/netnsutils/context_unix.go index 4dde6b4762..9c527f026e 100644 --- a/internal/testutils/netnsutils/context_unix.go +++ b/internal/testutils/netnsutils/context_unix.go @@ -8,6 +8,7 @@ import ( "strconv" "testing" + "github.com/docker/docker/internal/testutils" "github.com/docker/docker/libnetwork/ns" "github.com/pkg/errors" "github.com/vishvananda/netns" @@ -131,7 +132,7 @@ func (c *OSContext) restore(t *testing.T) { // t.Fatalf("%+v", err) // } // } -func (c *OSContext) Set() (func(Logger), error) { +func (c *OSContext) Set() (func(testutils.Logger), error) { runtime.LockOSThread() orig, err := netns.Get() if err != nil { @@ -146,7 +147,7 @@ func (c *OSContext) Set() (func(Logger), error) { tid := unix.Gettid() _, file, line, callerOK := runtime.Caller(0) - return func(log Logger) { + return func(log testutils.Logger) { if unix.Gettid() != tid { msg := "teardown function must be called from the same goroutine as c.Set()" if callerOK { diff --git a/internal/testutils/netnsutils/context_windows.go b/internal/testutils/netnsutils/context_windows.go index efc96298a1..eef0689c44 100644 --- a/internal/testutils/netnsutils/context_windows.go +++ b/internal/testutils/netnsutils/context_windows.go @@ -1,6 +1,10 @@ package netnsutils -import "testing" +import ( + "testing" + + "github.com/docker/docker/internal/testutils" +) type OSContext struct{} @@ -10,6 +14,6 @@ func SetupTestOSContextEx(*testing.T) *OSContext { func (*OSContext) Cleanup(t *testing.T) {} -func (*OSContext) Set() (func(Logger), error) { - return func(Logger) {}, nil +func (*OSContext) Set() (func(testutils.Logger), error) { + return func(testutils.Logger) {}, nil }