Skip to content

Commit

Permalink
Integration test for RmdirContents
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciopoppe committed Jan 11, 2022
1 parent fd5fdae commit 8c10065
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion integrationtests/filesystem_v2alpha1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func v2alpha1FilesystemTests(t *testing.T) {
err = os.Mkdir(targetStagePath, os.ModeDir)
require.Nil(t, err)
defer os.Remove(targetStagePath)
// Create a sym link
// Create a symlink
err = os.Symlink(targetStagePath, lnTargetStagePath)
require.Nil(t, err)
defer os.Remove(lnTargetStagePath)
Expand All @@ -147,4 +147,43 @@ func v2alpha1FilesystemTests(t *testing.T) {
require.Nil(t, err)
require.Equal(t, isSymlink.IsSymlink, false)
})
t.Run("RmdirContents", func(t *testing.T) {
client, err := v2alpha1client.NewClient()
require.Nil(t, err)
defer client.Close()

r1 := rand.New(rand.NewSource(time.Now().UnixNano()))
rand1 := r1.Intn(100)

rootPath := getKubeletPathForTest(fmt.Sprintf("testplugin-%d.csi.io", rand1), t)
// this line should delete the rootPath because only its content were deleted
defer os.RemoveAll(rootPath)

paths := []string{
filepath.Join(rootPath, "foo/goo/"),
filepath.Join(rootPath, "foo/bar/baz/"),
filepath.Join(rootPath, "alpha/beta/gamma/"),
}
for _, path := range paths {
err = os.MkdirAll(path, os.ModeDir)
require.Nil(t, err)
}

rmdirContentsRequest := &v2alpha1.RmdirContentsRequest{
Path: rootPath,
Force: true,
}
_, err = client.RmdirContents(context.Background(), rmdirContentsRequest)
require.Nil(t, err)

// the root path should exist
exists, err := pathExists(rootPath)
assert.True(t, exists, err)
// the root path children shouldn't exist
for _, path := range paths {
exists, err = pathExists(path)
assert.False(t, exists, err)
}
})

}

0 comments on commit 8c10065

Please sign in to comment.