Skip to content

Commit

Permalink
Add tests for populated volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenz authored and bobbypage committed Mar 10, 2021
1 parent 8adb218 commit d834777
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pkg/kubelet/kubelet_volumes_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestCleanupOrphanedPodDirs(t *testing.T) {
},
validateFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
return validateDirNotExists(filepath.Join(podDir, "volumes/plugin/name"))
return validateDirNotExists(podDir)
},
},
"pod-doesnot-exist-with-subpath": {
Expand All @@ -111,7 +111,7 @@ func TestCleanupOrphanedPodDirs(t *testing.T) {
},
validateFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
return validateDirNotExists(filepath.Join(podDir, "volume-subpaths/volume/container/index"))
return validateDirNotExists(podDir)
},
},
"pod-doesnot-exist-with-subpath-top": {
Expand All @@ -121,7 +121,35 @@ func TestCleanupOrphanedPodDirs(t *testing.T) {
},
validateFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
return validateDirNotExists(filepath.Join(podDir, "volume-subpaths"))
return validateDirNotExists(podDir)
},
},
"pod-doesnot-exists-with-populated-volume": {
prepareFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
volumePath := filepath.Join(podDir, "volumes/plugin/name")
if err := os.MkdirAll(volumePath, 0750); err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(volumePath, "test.txt"), []byte("test1"), 0640)
},
validateFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
return validateDirExists(filepath.Join(podDir, "volumes/plugin/name"))
},
},
"pod-doesnot-exists-with-populated-subpath": {
prepareFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
subPath := filepath.Join(podDir, "volume-subpaths/volume/container/index")
if err := os.MkdirAll(subPath, 0750); err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(subPath, "test.txt"), []byte("test1"), 0640)
},
validateFunc: func(kubelet *Kubelet) error {
podDir := kubelet.getPodDir("pod1uid")
return validateDirExists(filepath.Join(podDir, "volume-subpaths/volume/container/index"))
},
},
// TODO: test volume in volume-manager
Expand Down

0 comments on commit d834777

Please sign in to comment.