@@ -12,7 +12,7 @@ import (
12
12
13
13
func TestCreateVolume (t * testing.T ) {
14
14
t .Run ("Create a default size volume" , func (t * testing.T ) {
15
- d , _ := driver .NewTestDriver ()
15
+ d , _ := driver .NewTestDriver (nil )
16
16
17
17
resp , err := d .CreateVolume (context .Background (), & csi.CreateVolumeRequest {
18
18
Name : "foo" ,
@@ -34,7 +34,7 @@ func TestCreateVolume(t *testing.T) {
34
34
})
35
35
36
36
t .Run ("Disallow block volumes" , func (t * testing.T ) {
37
- d , _ := driver .NewTestDriver ()
37
+ d , _ := driver .NewTestDriver (nil )
38
38
39
39
_ , err := d .CreateVolume (context .Background (), & csi.CreateVolumeRequest {
40
40
Name : "foo" ,
@@ -51,7 +51,7 @@ func TestCreateVolume(t *testing.T) {
51
51
})
52
52
53
53
t .Run ("Create a specified size volume" , func (t * testing.T ) {
54
- d , _ := driver .NewTestDriver ()
54
+ d , _ := driver .NewTestDriver (nil )
55
55
56
56
_ , err := d .CreateVolume (context .Background (), & csi.CreateVolumeRequest {
57
57
Name : "foo" ,
@@ -73,10 +73,11 @@ func TestCreateVolume(t *testing.T) {
73
73
})
74
74
75
75
t .Run ("Don't create if the volume already exists and just return it" , func (t * testing.T ) {
76
- d , _ := driver .NewTestDriver ()
76
+ d , _ := driver .NewTestDriver (nil )
77
77
78
78
volume , err := d .CivoClient .NewVolume (& civogo.VolumeConfig {
79
- Name : "foo" ,
79
+ Name : "foo" ,
80
+ SizeGigabytes : 10 ,
80
81
})
81
82
assert .Nil (t , err )
82
83
@@ -101,7 +102,7 @@ func TestCreateVolume(t *testing.T) {
101
102
102
103
func TestDeleteVolume (t * testing.T ) {
103
104
t .Run ("Delete a volume" , func (t * testing.T ) {
104
- d , _ := driver .NewTestDriver ()
105
+ d , _ := driver .NewTestDriver (nil )
105
106
106
107
volume , err := d .CivoClient .NewVolume (& civogo.VolumeConfig {
107
108
Name : "foo" ,
@@ -120,12 +121,20 @@ func TestDeleteVolume(t *testing.T) {
120
121
121
122
func TestControllerPublishVolume (t * testing.T ) {
122
123
t .Run ("Publish a volume" , func (t * testing.T ) {
123
- d , _ := driver .NewTestDriver ()
124
-
125
- instance , err := d .CivoClient .CreateInstance (& civogo.InstanceConfig {
124
+ fc , _ := civogo .NewFakeClient ()
125
+ instanceID := "i-12345678"
126
+ fc .Clusters = []civogo.KubernetesCluster {{
127
+ ID : "12345678" ,
128
+ Instances : []civogo.KubernetesInstance {{
129
+ ID : instanceID ,
130
+ Hostname : "instance-1" ,
131
+ }},
132
+ }}
133
+ fc .Instances = []civogo.Instance {{
134
+ ID : instanceID ,
126
135
Hostname : "instance-1" ,
127
- })
128
- assert . Nil ( t , err )
136
+ }}
137
+ d , _ := driver . NewTestDriver ( fc )
129
138
130
139
volume , err := d .CivoClient .NewVolume (& civogo.VolumeConfig {
131
140
Name : "foo" ,
@@ -134,19 +143,20 @@ func TestControllerPublishVolume(t *testing.T) {
134
143
135
144
_ , err = d .ControllerPublishVolume (context .Background (), & csi.ControllerPublishVolumeRequest {
136
145
VolumeId : volume .ID ,
137
- NodeId : instance . ID ,
146
+ NodeId : instanceID ,
138
147
VolumeCapability : & csi.VolumeCapability {},
139
148
})
140
149
assert .Nil (t , err )
141
150
142
151
volumes , _ := d .CivoClient .ListVolumes ()
143
- assert .Equal (t , instance . ID , volumes [0 ].InstanceID )
152
+ assert .Equal (t , instanceID , volumes [0 ].InstanceID )
144
153
})
145
154
}
146
155
147
156
func TestControllerUnpublishVolume (t * testing.T ) {
148
157
t .Run ("Unpublish a volume if attached to the correct node" , func (t * testing.T ) {
149
- d , _ := driver .NewTestDriver ()
158
+ fc , _ := civogo .NewFakeClient ()
159
+ d , _ := driver .NewTestDriver (fc )
150
160
151
161
volume , err := d .CivoClient .NewVolume (& civogo.VolumeConfig {
152
162
Name : "foo" ,
@@ -167,7 +177,8 @@ func TestControllerUnpublishVolume(t *testing.T) {
167
177
})
168
178
169
179
t .Run ("Doesn't unpublish a volume if attached to a different node" , func (t * testing.T ) {
170
- d , _ := driver .NewTestDriver ()
180
+ fc , _ := civogo .NewFakeClient ()
181
+ d , _ := driver .NewTestDriver (fc )
171
182
172
183
volume , err := d .CivoClient .NewVolume (& civogo.VolumeConfig {
173
184
Name : "foo" ,
@@ -190,7 +201,8 @@ func TestControllerUnpublishVolume(t *testing.T) {
190
201
191
202
func TestListVolumes (t * testing.T ) {
192
203
t .Run ("Lists available existing volumes" , func (t * testing.T ) {
193
- d , _ := driver .NewTestDriver ()
204
+ fc , _ := civogo .NewFakeClient ()
205
+ d , _ := driver .NewTestDriver (fc )
194
206
195
207
volume , err := d .CivoClient .NewVolume (& civogo.VolumeConfig {
196
208
Name : "foo" ,
@@ -209,7 +221,8 @@ func TestListVolumes(t *testing.T) {
209
221
210
222
func TestGetCapacity (t * testing.T ) {
211
223
t .Run ("Has available capacity from usage and limit" , func (t * testing.T ) {
212
- d , _ := driver .NewTestDriver ()
224
+ fc , _ := civogo .NewFakeClient ()
225
+ d , _ := driver .NewTestDriver (fc )
213
226
214
227
civoClient , _ := civogo .NewFakeClient ()
215
228
d .CivoClient = civoClient
@@ -228,7 +241,8 @@ func TestGetCapacity(t *testing.T) {
228
241
})
229
242
230
243
t .Run ("Has no capacity from usage and limit" , func (t * testing.T ) {
231
- d , _ := driver .NewTestDriver ()
244
+ fc , _ := civogo .NewFakeClient ()
245
+ d , _ := driver .NewTestDriver (fc )
232
246
233
247
civoClient , _ := civogo .NewFakeClient ()
234
248
d .CivoClient = civoClient
@@ -247,7 +261,8 @@ func TestGetCapacity(t *testing.T) {
247
261
})
248
262
249
263
t .Run ("Has no capacity from volume count limit" , func (t * testing.T ) {
250
- d , _ := driver .NewTestDriver ()
264
+ fc , _ := civogo .NewFakeClient ()
265
+ d , _ := driver .NewTestDriver (fc )
251
266
252
267
civoClient , _ := civogo .NewFakeClient ()
253
268
d .CivoClient = civoClient
0 commit comments