@@ -125,7 +125,7 @@ func v2alpha1FilesystemTests(t *testing.T) {
125
125
err = os .Mkdir (targetStagePath , os .ModeDir )
126
126
require .Nil (t , err )
127
127
defer os .Remove (targetStagePath )
128
- // Create a sym link
128
+ // Create a symlink
129
129
err = os .Symlink (targetStagePath , lnTargetStagePath )
130
130
require .Nil (t , err )
131
131
defer os .Remove (lnTargetStagePath )
@@ -147,4 +147,43 @@ func v2alpha1FilesystemTests(t *testing.T) {
147
147
require .Nil (t , err )
148
148
require .Equal (t , isSymlink .IsSymlink , false )
149
149
})
150
+ t .Run ("RmdirContents" , func (t * testing.T ) {
151
+ client , err := v2alpha1client .NewClient ()
152
+ require .Nil (t , err )
153
+ defer client .Close ()
154
+
155
+ r1 := rand .New (rand .NewSource (time .Now ().UnixNano ()))
156
+ rand1 := r1 .Intn (100 )
157
+
158
+ rootPath := getKubeletPathForTest (fmt .Sprintf ("testplugin-%d.csi.io" , rand1 ), t )
159
+ // this line should delete the rootPath because only its content were deleted
160
+ defer os .RemoveAll (rootPath )
161
+
162
+ paths := []string {
163
+ filepath .Join (rootPath , "foo/goo/" ),
164
+ filepath .Join (rootPath , "foo/bar/baz/" ),
165
+ filepath .Join (rootPath , "alpha/beta/gamma/" ),
166
+ }
167
+ for _ , path := range paths {
168
+ err = os .MkdirAll (path , os .ModeDir )
169
+ require .Nil (t , err )
170
+ }
171
+
172
+ rmdirContentsRequest := & v2alpha1.RmdirContentsRequest {
173
+ Path : rootPath ,
174
+ Force : true ,
175
+ }
176
+ _ , err = client .RmdirContents (context .Background (), rmdirContentsRequest )
177
+ require .Nil (t , err )
178
+
179
+ // the root path should exist
180
+ exists , err := pathExists (rootPath )
181
+ assert .True (t , exists , err )
182
+ // the root path children shouldn't exist
183
+ for _ , path := range paths {
184
+ exists , err = pathExists (path )
185
+ assert .False (t , exists , err )
186
+ }
187
+ })
188
+
150
189
}
0 commit comments