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 <brice.rising@slalom.com>
pull/6738/head
Brice Rising 7 years ago committed by Yagnesh Mistry
parent 60bd2a56fd
commit 3469c9a17c

@ -8,6 +8,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path/filepath" "path/filepath"
"runtime" "runtime"
"testing" "testing"
@ -147,6 +148,13 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) {
t.Skip("skipping on windows") 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 var srcdir, dstdir string
cleanup := setupInaccessibleDir(t, func(dir string) error { cleanup := setupInaccessibleDir(t, func(dir string) error {
@ -175,6 +183,13 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
t.Skip("skipping on windows") 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 var srcdir, dstdir string
dir, err := ioutil.TempDir("", "helm-tmp") dir, err := ioutil.TempDir("", "helm-tmp")
@ -264,6 +279,13 @@ func TestCopyDirFailOpen(t *testing.T) {
t.Skip("skipping on windows") 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 var srcdir, dstdir string
dir, err := ioutil.TempDir("", "helm-tmp") dir, err := ioutil.TempDir("", "helm-tmp")
@ -422,6 +444,13 @@ func TestCopyFileFail(t *testing.T) {
t.Skip("skipping on windows") 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") dir, err := ioutil.TempDir("", "helm-tmp")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -501,6 +530,14 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
} }
func TestIsDir(t *testing.T) { 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() wd, err := os.Getwd()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -546,6 +583,14 @@ func TestIsDir(t *testing.T) {
} }
func TestIsSymlink(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") dir, err := ioutil.TempDir("", "helm-tmp")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

Loading…
Cancel
Save