1
1
package integrationtests
2
2
3
3
import (
4
- "context"
5
- "fmt"
6
- "math/rand"
7
4
"os"
8
5
"testing"
9
- "time"
10
-
11
- "github.com/stretchr/testify/assert"
12
- "github.com/stretchr/testify/require"
13
-
14
- "github.com/kubernetes-csi/csi-proxy/client/api/filesystem/v1beta2"
15
- v1beta2client "github.com/kubernetes-csi/csi-proxy/client/groups/filesystem/v1beta2"
16
6
)
17
7
18
8
func pathExists (path string ) (bool , error ) {
@@ -27,143 +17,13 @@ func pathExists(path string) (bool, error) {
27
17
}
28
18
29
19
func TestFilesystemAPIGroup (t * testing.T ) {
30
- t .Run ("PathExists positive" , func (t * testing.T ) {
31
- skipTestOnCondition (t , isRunningOnGhActions ())
32
-
33
- client , err := v1beta2client .NewClient ()
34
- require .Nil (t , err )
35
- defer client .Close ()
36
-
37
- s1 := rand .NewSource (time .Now ().UnixNano ())
38
- r1 := rand .New (s1 )
39
-
40
- // simulate FS operations around staging a volume on a node
41
- stagepath := getWorkDirPath (fmt .Sprintf ("testplugin-%d.csi.io\\ volume%d" , r1 .Intn (100 ), r1 .Intn (100 )), t )
42
- mkdirReq := & v1beta2.MkdirRequest {
43
- Path : stagepath ,
44
- Context : v1beta2 .PathContext_PLUGIN ,
45
- }
46
- mkdirRsp , err := client .Mkdir (context .Background (), mkdirReq )
47
- if assert .Nil (t , err ) {
48
- assert .Equal (t , "" , mkdirRsp .Error )
49
- }
50
-
51
- exists , err := pathExists (stagepath )
52
- assert .True (t , exists , err )
53
-
54
- // simulate operations around publishing a volume to a pod
55
- podpath := getWorkDirPath (fmt .Sprintf ("test-pod-id\\ volumes\\ kubernetes.io~csi\\ pvc-test%d" , r1 .Intn (100 )), t )
56
- mkdirReq = & v1beta2.MkdirRequest {
57
- Path : podpath ,
58
- Context : v1beta2 .PathContext_POD ,
59
- }
60
- mkdirRsp , err = client .Mkdir (context .Background (), mkdirReq )
61
- if assert .Nil (t , err ) {
62
- assert .Equal (t , "" , mkdirRsp .Error )
63
- }
64
- linkReq := & v1beta2.LinkPathRequest {
65
- TargetPath : stagepath ,
66
- SourcePath : podpath + "\\ rootvol" ,
67
- }
68
- linkRsp , err := client .LinkPath (context .Background (), linkReq )
69
- if assert .Nil (t , err ) {
70
- assert .Equal (t , "" , linkRsp .Error )
71
- }
72
-
73
- exists , err = pathExists (podpath + "\\ rootvol" )
74
- assert .True (t , exists , err )
75
-
76
- // cleanup pvpath
77
- rmdirReq := & v1beta2.RmdirRequest {
78
- Path : podpath ,
79
- Context : v1beta2 .PathContext_POD ,
80
- Force : true ,
81
- }
82
- rmdirRsp , err := client .Rmdir (context .Background (), rmdirReq )
83
- if assert .Nil (t , err ) {
84
- assert .Equal (t , "" , rmdirRsp .Error )
85
- }
86
-
87
- exists , err = pathExists (podpath )
88
- assert .False (t , exists , err )
89
-
90
- // cleanup plugin path
91
- rmdirReq = & v1beta2.RmdirRequest {
92
- Path : stagepath ,
93
- Context : v1beta2 .PathContext_PLUGIN ,
94
- Force : true ,
95
- }
96
- rmdirRsp , err = client .Rmdir (context .Background (), rmdirReq )
97
- if assert .Nil (t , err ) {
98
- assert .Equal (t , "" , rmdirRsp .Error )
99
- }
100
-
101
- exists , err = pathExists (stagepath )
102
- assert .False (t , exists , err )
20
+ t .Run ("v1beta2FilesystemTests" , func (t * testing.T ) {
21
+ v1beta2FilesystemTests (t )
103
22
})
104
- t .Run ("IsMount" , func (t * testing.T ) {
105
- client , err := v1beta2client .NewClient ()
106
- require .Nil (t , err )
107
- defer client .Close ()
108
-
109
- s1 := rand .NewSource (time .Now ().UnixNano ())
110
- r1 := rand .New (s1 )
111
- rand1 := r1 .Intn (100 )
112
- rand2 := r1 .Intn (100 )
113
-
114
- testDir := getWorkDirPath (fmt .Sprintf ("testplugin-%d.csi.io" , rand1 ), t )
115
- err = os .MkdirAll (testDir , os .ModeDir )
116
- require .Nil (t , err )
117
- defer os .RemoveAll (testDir )
118
-
119
- // 1. Check the isMount on a path which does not exist. Failure scenario.
120
- stagepath := getWorkDirPath (fmt .Sprintf ("testplugin-%d.csi.io\\ volume%d" , rand1 , rand2 ), t )
121
- isMountRequest := & v1beta2.IsMountPointRequest {
122
- Path : stagepath ,
123
- }
124
- isMountResponse , err := client .IsMountPoint (context .Background (), isMountRequest )
125
- require .NotNil (t , err )
126
-
127
- // 2. Create the directory. This time its not a mount point. Failure scenario.
128
- err = os .Mkdir (stagepath , os .ModeDir )
129
- require .Nil (t , err )
130
- defer os .Remove (stagepath )
131
- isMountRequest = & v1beta2.IsMountPointRequest {
132
- Path : stagepath ,
133
- }
134
- isMountResponse , err = client .IsMountPoint (context .Background (), isMountRequest )
135
- require .Nil (t , err )
136
- require .Equal (t , isMountResponse .IsMountPoint , false )
137
-
138
- err = os .Remove (stagepath )
139
- require .Nil (t , err )
140
- targetStagePath := getWorkDirPath (fmt .Sprintf ("testplugin-%d.csi.io\\ volume%d-tgt" , rand1 , rand2 ), t )
141
- lnTargetStagePath := getWorkDirPath (fmt .Sprintf ("testplugin-%d.csi.io\\ volume%d-tgt-ln" , rand1 , rand2 ), t )
142
-
143
- // 3. Create soft link to the directory and make sure target exists. Success scenario.
144
- err = os .Mkdir (targetStagePath , os .ModeDir )
145
- require .Nil (t , err )
146
- defer os .Remove (targetStagePath )
147
- // Create a sym link
148
- err = os .Symlink (targetStagePath , lnTargetStagePath )
149
- require .Nil (t , err )
150
- defer os .Remove (lnTargetStagePath )
151
-
152
- isMountRequest = & v1beta2.IsMountPointRequest {
153
- Path : lnTargetStagePath ,
154
- }
155
- isMountResponse , err = client .IsMountPoint (context .Background (), isMountRequest )
156
- require .Nil (t , err )
157
- require .Equal (t , isMountResponse .IsMountPoint , true )
158
-
159
- // 4. Remove the path. Failure scenario.
160
- err = os .Remove (targetStagePath )
161
- require .Nil (t , err )
162
- isMountRequest = & v1beta2.IsMountPointRequest {
163
- Path : lnTargetStagePath ,
164
- }
165
- isMountResponse , err = client .IsMountPoint (context .Background (), isMountRequest )
166
- require .Nil (t , err )
167
- require .Equal (t , isMountResponse .IsMountPoint , false )
23
+ t .Run ("v1beta1FilesystemTests" , func (t * testing.T ) {
24
+ v1beta1FilesystemTests (t )
25
+ })
26
+ t .Run ("v1alpha1FilesystemTests" , func (t * testing.T ) {
27
+ v1alpha1FilesystemTests (t )
168
28
})
169
29
}
0 commit comments