From 3469c9a17c3a78164b8160c3c2bb60063d829457 Mon Sep 17 00:00:00 2001 From: Brice Rising Date: Mon, 10 Dec 2018 14:35:14 -0500 Subject: [PATCH] Skip inaccessible file tests for root Root can access all files, so the tests for inaccessible files were failing. Now we will skip these tests when running as root. Signed-off-by: Brice Rising --- pkg/fsutil/fs_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/fsutil/fs_test.go b/pkg/fsutil/fs_test.go index c04a8ddd1..994683725 100644 --- a/pkg/fsutil/fs_test.go +++ b/pkg/fsutil/fs_test.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "os/exec" + "os/user" "path/filepath" "runtime" "testing" @@ -147,6 +148,13 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) { t.Skip("skipping on windows") } + var current_user, err = user.Current() + + if current_user.Name == "root" { + // Skipping if root, because all files are accessible + t.Skip("Skipping for root user") + } + var srcdir, dstdir string cleanup := setupInaccessibleDir(t, func(dir string) error { @@ -175,6 +183,13 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) { t.Skip("skipping on windows") } + var current_user, err = user.Current() + + if current_user.Name == "root" { + // Skipping if root, because all files are accessible + t.Skip("Skipping for root user") + } + var srcdir, dstdir string dir, err := ioutil.TempDir("", "helm-tmp") @@ -264,6 +279,13 @@ func TestCopyDirFailOpen(t *testing.T) { t.Skip("skipping on windows") } + var current_user, err = user.Current() + + if current_user.Name == "root" { + // Skipping if root, because all files are accessible + t.Skip("Skipping for root user") + } + var srcdir, dstdir string dir, err := ioutil.TempDir("", "helm-tmp") @@ -422,6 +444,13 @@ func TestCopyFileFail(t *testing.T) { t.Skip("skipping on windows") } + var current_user, err = user.Current() + + if current_user.Name == "root" { + // Skipping if root, because all files are accessible + t.Skip("Skipping for root user") + } + dir, err := ioutil.TempDir("", "helm-tmp") if err != nil { t.Fatal(err) @@ -501,6 +530,14 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() { } func TestIsDir(t *testing.T) { + + var current_user, err = user.Current() + + if current_user.Name == "root" { + // Skipping if root, because all files are accessible + t.Skip("Skipping for root user") + } + wd, err := os.Getwd() if err != nil { t.Fatal(err) @@ -546,6 +583,14 @@ func TestIsDir(t *testing.T) { } func TestIsSymlink(t *testing.T) { + + var current_user, err = user.Current() + + if current_user.Name == "root" { + // Skipping if root, because all files are accessible + t.Skip("Skipping for root user") + } + dir, err := ioutil.TempDir("", "helm-tmp") if err != nil { t.Fatal(err)