Browse Source

Merge pull request #36505 from kolyshkin/pkg-mount-tests

pkg/mount unit tests: skip some test under non-root
Akihiro Suda 7 years ago
parent
commit
4a1d35c546

+ 8 - 0
pkg/mount/mount_unix_test.go

@@ -25,6 +25,10 @@ func TestMountOptionsParsing(t *testing.T) {
 }
 }
 
 
 func TestMounted(t *testing.T) {
 func TestMounted(t *testing.T) {
+	if os.Getuid() != 0 {
+		t.Skip("root required")
+	}
+
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -76,6 +80,10 @@ func TestMounted(t *testing.T) {
 }
 }
 
 
 func TestMountReadonly(t *testing.T) {
 func TestMountReadonly(t *testing.T) {
+	if os.Getuid() != 0 {
+		t.Skip("root required")
+	}
+
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)

+ 1 - 1
pkg/mount/mounter_linux_test.go

@@ -14,7 +14,7 @@ import (
 
 
 func TestMount(t *testing.T) {
 func TestMount(t *testing.T) {
 	if os.Getuid() != 0 {
 	if os.Getuid() != 0 {
-		t.Skip("not root tests would fail")
+		t.Skip("root required")
 	}
 	}
 
 
 	source, err := ioutil.TempDir("", "mount-test-source-")
 	source, err := ioutil.TempDir("", "mount-test-source-")

+ 16 - 0
pkg/mount/sharedsubtree_linux_test.go

@@ -12,6 +12,10 @@ import (
 
 
 // nothing is propagated in or out
 // nothing is propagated in or out
 func TestSubtreePrivate(t *testing.T) {
 func TestSubtreePrivate(t *testing.T) {
+	if os.Getuid() != 0 {
+		t.Skip("root required")
+	}
+
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -110,6 +114,10 @@ func TestSubtreePrivate(t *testing.T) {
 // Testing that when a target is a shared mount,
 // Testing that when a target is a shared mount,
 // then child mounts propagate to the source
 // then child mounts propagate to the source
 func TestSubtreeShared(t *testing.T) {
 func TestSubtreeShared(t *testing.T) {
+	if os.Getuid() != 0 {
+		t.Skip("root required")
+	}
+
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -178,6 +186,10 @@ func TestSubtreeShared(t *testing.T) {
 // testing that mounts to a shared source show up in the slave target,
 // testing that mounts to a shared source show up in the slave target,
 // and that mounts into a slave target do _not_ show up in the shared source
 // and that mounts into a slave target do _not_ show up in the shared source
 func TestSubtreeSharedSlave(t *testing.T) {
 func TestSubtreeSharedSlave(t *testing.T) {
+	if os.Getuid() != 0 {
+		t.Skip("root required")
+	}
+
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -282,6 +294,10 @@ func TestSubtreeSharedSlave(t *testing.T) {
 }
 }
 
 
 func TestSubtreeUnbindable(t *testing.T) {
 func TestSubtreeUnbindable(t *testing.T) {
+	if os.Getuid() != 0 {
+		t.Skip("root required")
+	}
+
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	tmp := path.Join(os.TempDir(), "mount-tests")
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 	if err := os.MkdirAll(tmp, 0777); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)