Browse Source

internal/testutils/netnsutils: move utils that were not used on Windows

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 year ago
parent
commit
05deecaa45

+ 0 - 36
internal/testutils/netnsutils/context.go

@@ -1,36 +0,0 @@
-package netnsutils
-
-import (
-	"testing"
-)
-
-// SetupTestOSContext joins the current goroutine to a new network namespace,
-// and returns its associated teardown function.
-//
-// Example usage:
-//
-//	defer SetupTestOSContext(t)()
-func SetupTestOSContext(t *testing.T) func() {
-	c := SetupTestOSContextEx(t)
-	return func() { c.Cleanup(t) }
-}
-
-// Go starts running fn in a new goroutine inside the test OS context.
-func (c *OSContext) Go(t *testing.T, fn func()) {
-	t.Helper()
-	errCh := make(chan error, 1)
-	go func() {
-		teardown, err := c.Set()
-		if err != nil {
-			errCh <- err
-			return
-		}
-		defer teardown(t)
-		close(errCh)
-		fn()
-	}()
-
-	if err := <-errCh; err != nil {
-		t.Fatalf("%+v", err)
-	}
-}

+ 31 - 0
internal/testutils/netnsutils/context_unix.go

@@ -23,6 +23,17 @@ type OSContext struct {
 	caller string // The file:line where SetupTestOSContextEx was called, for interpolating into error messages.
 }
 
+// SetupTestOSContext joins the current goroutine to a new network namespace,
+// and returns its associated teardown function.
+//
+// Example usage:
+//
+//	defer SetupTestOSContext(t)()
+func SetupTestOSContext(t *testing.T) func() {
+	c := SetupTestOSContextEx(t)
+	return func() { c.Cleanup(t) }
+}
+
 // SetupTestOSContextEx joins the current goroutine to a new network namespace.
 //
 // Compared to [SetupTestOSContext], this function allows goroutines to be
@@ -167,3 +178,23 @@ func (c *OSContext) Set() (func(testutils.Logger), error) {
 		}
 	}, nil
 }
+
+// Go starts running fn in a new goroutine inside the test OS context.
+func (c *OSContext) Go(t *testing.T, fn func()) {
+	t.Helper()
+	errCh := make(chan error, 1)
+	go func() {
+		teardown, err := c.Set()
+		if err != nil {
+			errCh <- err
+			return
+		}
+		defer teardown(t)
+		close(errCh)
+		fn()
+	}()
+
+	if err := <-errCh; err != nil {
+		t.Fatalf("%+v", err)
+	}
+}

+ 4 - 15
internal/testutils/netnsutils/context_windows.go

@@ -1,19 +1,8 @@
 package netnsutils
 
-import (
-	"testing"
+import "testing"
 
-	"github.com/docker/docker/internal/testutils"
-)
-
-type OSContext struct{}
-
-func SetupTestOSContextEx(*testing.T) *OSContext {
-	return nil
-}
-
-func (*OSContext) Cleanup(t *testing.T) {}
-
-func (*OSContext) Set() (func(testutils.Logger), error) {
-	return func(testutils.Logger) {}, nil
+// SetupTestOSContext is a no-op on Windows.
+func SetupTestOSContext(*testing.T) func() {
+	return func() {}
 }