mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
testutils: move Logger interface to testutils
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
10
internal/testutils/logger.go
Normal file
10
internal/testutils/logger.go
Normal file
@@ -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)
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user