Bladeren bron

quota: remove gotest.tools from testhelpers

gotest.tools has an init() which registers a '-update' flag;
https://github.com/gotestyourself/gotest.tools/blob/a80f057529047c44e1a85d0d017b200787e537e0/internal/source/update.go#L21-L23

The quota helper contains a testhelpers file, which is meant for usage
in (integration) tests, but as it's in the same pacakge as production
code, would also trigger the gotest.tools init.

This patch removes the gotest.tools code from this file.

Before this patch:

    $ (exec -a libnetwork-setkey "$(which dockerd)" -help)
    Usage of libnetwork-setkey:
      -exec-root string
            docker exec root (default "/run/docker")
      -update
            update golden values

With this patch applied:

    $ (exec -a libnetwork-setkey "$(which dockerd)" -help)
    Usage of libnetwork-setkey:
      -exec-root string
            docker exec root (default "/run/docker")

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 1aa17222e7a350971ae00ea75b34caaa9db382f6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 jaren geleden
bovenliggende
commit
9f8a92473b
1 gewijzigde bestanden met toevoegingen van 19 en 12 verwijderingen
  1. 19 12
      quota/testhelpers.go

+ 19 - 12
quota/testhelpers.go

@@ -9,8 +9,6 @@ import (
 	"testing"
 
 	"golang.org/x/sys/unix"
-	"gotest.tools/v3/assert"
-	"gotest.tools/v3/fs"
 )
 
 const imageSize = 64 * 1024 * 1024
@@ -79,10 +77,7 @@ func WrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *test
 			mountOptions = mountOptions + ",prjquota"
 		}
 
-		mountPointDir := fs.NewDir(t, "xfs-mountPoint")
-		defer mountPointDir.Remove()
-		mountPoint := mountPointDir.Path()
-
+		mountPoint := t.TempDir()
 		out, err := exec.Command("mount", "-o", mountOptions, imageFileName, mountPoint).CombinedOutput()
 		if err != nil {
 			_, err := os.Stat("/proc/fs/xfs")
@@ -91,17 +86,25 @@ func WrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *test
 			}
 		}
 
-		assert.NilError(t, err, "mount failed: %s", out)
+		if err != nil {
+			t.Fatalf("assertion failed: error is not nil: %v: mount failed: %s", err, out)
+		}
 
 		defer func() {
-			assert.NilError(t, unix.Unmount(mountPoint, 0))
+			if err := unix.Unmount(mountPoint, 0); err != nil {
+				t.Fatalf("assertion failed: error is not nil: %v", err)
+			}
 		}()
 
 		backingFsDev, err := makeBackingFsDev(mountPoint)
-		assert.NilError(t, err)
+		if err != nil {
+			t.Fatalf("assertion failed: error is not nil: %v", err)
+		}
 
 		testDir, err := os.MkdirTemp(mountPoint, "per-test")
-		assert.NilError(t, err)
+		if err != nil {
+			t.Fatalf("assertion failed: error is not nil: %v", err)
+		}
 		defer os.RemoveAll(testDir)
 
 		testFunc(t, mountPoint, backingFsDev, testDir)
@@ -113,10 +116,14 @@ func WrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *test
 func WrapQuotaTest(testFunc func(t *testing.T, ctrl *Control, mountPoint, testDir, testSubDir string)) func(t *testing.T, mountPoint, backingFsDev, testDir string) {
 	return func(t *testing.T, mountPoint, backingFsDev, testDir string) {
 		ctrl, err := NewControl(testDir)
-		assert.NilError(t, err)
+		if err != nil {
+			t.Fatalf("assertion failed: error is not nil: %v", err)
+		}
 
 		testSubDir, err := os.MkdirTemp(testDir, "quota-test")
-		assert.NilError(t, err)
+		if err != nil {
+			t.Fatalf("assertion failed: error is not nil: %v", err)
+		}
 		testFunc(t, ctrl, mountPoint, testDir, testSubDir)
 	}
 }