Merge pull request #4038 from AkihiroSuda/etcd-4007
pkg/fileutil: skip TestIsDirWriteable when running as rootrelease-2.3
commit
22b3b3e07a
|
@ -17,6 +17,7 @@ package fileutil
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -34,6 +35,17 @@ func TestIsDirWriteable(t *testing.T) {
|
||||||
if err := os.Chmod(tmpdir, 0444); err != nil {
|
if err := os.Chmod(tmpdir, 0444); err != nil {
|
||||||
t.Fatalf("unexpected os.Chmod error: %v", err)
|
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 {
|
if err := IsDirWriteable(tmpdir); err == nil {
|
||||||
t.Fatalf("expected IsDirWriteable to error")
|
t.Fatalf("expected IsDirWriteable to error")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue