testutils: move Logger interface to testutils

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
Albin Kerouanton 2023-07-26 21:13:45 +02:00
parent 492c09276d
commit 31d09f6ee9
No known key found for this signature in database
GPG key ID: 630B8E1DCBDB1864
4 changed files with 23 additions and 13 deletions

View 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)

View file

@ -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.

View file

@ -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 {

View file

@ -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
}