Skip to content

Commit e82f027

Browse files
committed
IsMountPoint test
1 parent 542bd69 commit e82f027

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

integrationtests/filesystem_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

internal/server/filesystem/server_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func (fakeFileSystemAPI) LinkPath(tgt string, src string) error {
2323
return nil
2424
}
2525

26+
func (fakeFileSystemAPI) IsMountPoint(path string) (bool, error) {
27+
return true, nil
28+
}
29+
2630
func TestMkdirWindows(t *testing.T) {
2731
v1alpha1, err := apiversion.NewVersion("v1alpha1")
2832
if err != nil {

0 commit comments

Comments
 (0)