Skip to content

Commit

Permalink
add unit test for check unmounted behavior of Unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
mochizuki875 committed Jan 11, 2023
1 parent 368fd9d commit bf77290
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions staging/src/k8s.io/mount-utils/mount_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"reflect"
"strings"
"testing"
"time"

utilexec "k8s.io/utils/exec"
testexec "k8s.io/utils/exec/testing"
Expand Down Expand Up @@ -620,3 +621,28 @@ func makeFakeCommandAction(stdout string, err error) testexec.FakeCommandAction
return testexec.InitFakeCmd(&c, cmd, args...)
}
}

func TestNotMountedBehaviorOfUnmount(t *testing.T) {
target, err := ioutil.TempDir("", "kubelet-umount")
if err != nil {
t.Errorf("Cannot create temp dir: %v", err)
}

defer os.RemoveAll(target)

m := Mounter{withSafeNotMountedBehavior: true}
if err = m.Unmount(target); err != nil {
t.Errorf(`Expect complete Unmount(), but it dose not: %v`, err)
}

if err = tryUnmount(target, m.withSafeNotMountedBehavior, time.Minute); err != nil {
t.Errorf(`Expect complete tryUnmount(), but it does not: %v`, err)
}

// forceUmount exec "umount -f", so skip this case if user is not root.
if os.Getuid() == 0 {
if err = forceUmount(target, m.withSafeNotMountedBehavior); err != nil {
t.Errorf(`Expect complete forceUnmount(), but it does not: %v`, err)
}
}
}

0 comments on commit bf77290

Please sign in to comment.