From 058f1449d6719df9d650aad905a387d22c9baa70 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 22 Dec 2015 15:08:54 +0900 Subject: [PATCH] pkg/fileutil: skip TestIsDirWriteable when running as root --- pkg/fileutil/fileutil_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/fileutil/fileutil_test.go b/pkg/fileutil/fileutil_test.go index 89d511cbc..415d53986 100644 --- a/pkg/fileutil/fileutil_test.go +++ b/pkg/fileutil/fileutil_test.go @@ -17,6 +17,7 @@ package fileutil import ( "io/ioutil" "os" + "os/user" "path/filepath" "reflect" "testing" @@ -34,6 +35,17 @@ func TestIsDirWriteable(t *testing.T) { if err := os.Chmod(tmpdir, 0444); err != nil { t.Fatalf("unexpected os.Chmod error: %v", err) } + me, err := user.Current() + if err != nil { + // err can be non-nil when cross compiled + // http://stackoverflow.com/questions/20609415/cross-compiling-user-current-not-implemented-on-linux-amd64 + t.Skipf("failed to get current user: %v", err) + } + if me.Name == "root" || me.Name == "Administrator" { + // ideally we should check CAP_DAC_OVERRIDE. + // but it does not matter for tests. + t.Skipf("running as a superuser") + } if err := IsDirWriteable(tmpdir); err == nil { t.Fatalf("expected IsDirWriteable to error") }