@@ -99,4 +99,70 @@ func TestFilesystemAPIGroup(t *testing.T) {
9999 exists , err = pathExists (stagepath )
100100 assert .False (t , exists , err )
101101 })
102+ t .Run ("IsMount" , func (t * testing.T ) {
103+ client , err := v1alpha1client .NewClient ()
104+ require .Nil (t , err )
105+ defer client .Close ()
106+
107+ s1 := rand .NewSource (time .Now ().UnixNano ())
108+ r1 := rand .New (s1 )
109+ rand1 := r1 .Intn (100 )
110+ rand2 := r1 .Intn (100 )
111+
112+ testDir := fmt .Sprintf ("C:\\ var\\ lib\\ kubelet\\ plugins\\ testplugin-%d.csi.io" , rand1 )
113+ err = os .MkdirAll (testDir , os .ModeDir )
114+ require .Nil (t , err )
115+ defer os .RemoveAll (testDir )
116+
117+ // 1. Check the isMount on a path which does not exist. Failure scenario.
118+ stagepath := fmt .Sprintf ("C:\\ var\\ lib\\ kubelet\\ plugins\\ testplugin-%d.csi.io\\ volume%d" , rand1 , rand2 )
119+ isMountRequest := & v1alpha1.IsMountPointRequest {
120+ Path : stagepath ,
121+ }
122+ isMountResponse , err := client .IsMountPoint (context .Background (), isMountRequest )
123+ require .Nil (t , err )
124+ require .Equal (t , isMountResponse .IsMountPoint , false )
125+
126+ // 2. Create the directory. This time its not a mount point. Failure scenario.
127+ err = os .Mkdir (stagepath , os .ModeDir )
128+ require .Nil (t , err )
129+ defer os .Remove (stagepath )
130+ isMountRequest = & v1alpha1.IsMountPointRequest {
131+ Path : stagepath ,
132+ }
133+ isMountResponse , err = client .IsMountPoint (context .Background (), isMountRequest )
134+ require .Nil (t , err )
135+ require .Equal (t , isMountResponse .IsMountPoint , false )
136+
137+ err = os .Remove (stagepath )
138+ require .Nil (t , err )
139+ targetStagePath := fmt .Sprintf ("C:\\ var\\ lib\\ kubelet\\ plugins\\ testplugin-%d.csi.io\\ volume%d-tgt" , rand1 , rand2 )
140+ lnTargetStagePath := fmt .Sprintf ("C:\\ var\\ lib\\ kubelet\\ plugins\\ testplugin-%d.csi.io\\ volume%d-tgt-ln" , rand1 , rand2 )
141+
142+ // 3. Create soft link to the directory and make sure target exists. Success scenario.
143+ os .Mkdir (targetStagePath , os .ModeDir )
144+ require .Nil (t , err )
145+ defer os .Remove (targetStagePath )
146+ // Create a sym link
147+ err = os .Symlink (targetStagePath , lnTargetStagePath )
148+ require .Nil (t , err )
149+ defer os .Remove (lnTargetStagePath )
150+
151+ isMountRequest = & v1alpha1.IsMountPointRequest {
152+ Path : lnTargetStagePath ,
153+ }
154+ isMountResponse , err = client .IsMountPoint (context .Background (), isMountRequest )
155+ require .Nil (t , err )
156+ require .Equal (t , isMountResponse .IsMountPoint , true )
157+
158+ // 4. Remove the path. Failure scenario.
159+ err = os .Remove (targetStagePath )
160+ require .Nil (t , err )
161+ isMountRequest = & v1alpha1.IsMountPointRequest {
162+ Path : lnTargetStagePath ,
163+ }
164+ isMountResponse , err = client .IsMountPoint (context .Background (), isMountRequest )
165+ require .Nil (t , err )
166+ require .Equal (t , isMountResponse .IsMountPoint , false )
167+ })
102168}
0 commit comments