mirror of https://github.com/k3s-io/k3s
Ignore the sticky gid mode bit when a test is running on memory EmptyDir
While running unit tests for perf on a Kube cluster with a memory backed emptydir as TMPDIR, TestSafeMakeDir failed with: ``` --- FAIL: TestSafeMakeDir (0.01s) mount_linux_test.go:661: test "directory-exists": expected permissions 20000000750, got 20020000750 ``` (TMPDIR set to /tmp/volume, /tmp/volume is EmptyDir with type Memory) The test doesn't actually care about `os.ModeSetgid`, so specifically mask it out when testing this way.pull/564/head
parent
139a13d312
commit
7f01e23380
|
@ -633,36 +633,43 @@ func TestSafeMakeDir(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
klog.V(4).Infof("test %q", test.name)
|
||||
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
test.prepare(base)
|
||||
pathToCreate := filepath.Join(base, test.path)
|
||||
err = doSafeMakeDir(pathToCreate, base, test.perm)
|
||||
if err != nil && !test.expectError {
|
||||
t.Errorf("test %q: %s", test.name, err)
|
||||
}
|
||||
if err != nil {
|
||||
klog.Infof("got error: %s", err)
|
||||
}
|
||||
if err == nil && test.expectError {
|
||||
t.Errorf("test %q: expected error, got none", test.name)
|
||||
}
|
||||
|
||||
if test.checkPath != "" {
|
||||
st, err := os.Stat(filepath.Join(base, test.checkPath))
|
||||
for i := range tests {
|
||||
test := tests[i]
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
base, err := ioutil.TempDir("", "safe-make-dir-"+test.name+"-")
|
||||
if err != nil {
|
||||
t.Errorf("test %q: cannot read path %s", test.name, test.checkPath)
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
if st.Mode() != test.perm {
|
||||
t.Errorf("test %q: expected permissions %o, got %o", test.name, test.perm, st.Mode())
|
||||
defer os.RemoveAll(base)
|
||||
test.prepare(base)
|
||||
pathToCreate := filepath.Join(base, test.path)
|
||||
err = doSafeMakeDir(pathToCreate, base, test.perm)
|
||||
if err != nil && !test.expectError {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err != nil {
|
||||
t.Logf("got error: %s", err)
|
||||
}
|
||||
if err == nil && test.expectError {
|
||||
t.Fatalf("expected error, got none")
|
||||
}
|
||||
}
|
||||
|
||||
os.RemoveAll(base)
|
||||
if test.checkPath != "" {
|
||||
st, err := os.Stat(filepath.Join(base, test.checkPath))
|
||||
if err != nil {
|
||||
t.Fatalf("cannot read path %s", test.checkPath)
|
||||
}
|
||||
actualMode := st.Mode()
|
||||
if actualMode != test.perm {
|
||||
if actualMode^test.perm == os.ModeSetgid && test.perm&os.ModeSetgid == 0 {
|
||||
// when TMPDIR is a kubernetes emptydir, the sticky gid bit is set due to fsgroup
|
||||
t.Logf("masking bit from %o", actualMode)
|
||||
} else {
|
||||
t.Errorf("expected permissions %o, got %o (%b)", test.perm, actualMode, test.perm^actualMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue