@@ -59,11 +59,10 @@ var (
59
59
Segments : map [string ]string {common .TopologyKeyZone : metadataservice .FakeZone },
60
60
},
61
61
}
62
- testVolumeID = fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , zone , name )
63
- region , _ = common .GetRegionFromZones ([]string {zone })
64
- testRegionalID = fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , project , region , name )
65
- testSnapshotID = fmt .Sprintf ("projects/%s/global/snapshots/%s" , project , name )
66
- totalSnapshotsNumber = 5
62
+ testVolumeID = fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , zone , name )
63
+ region , _ = common .GetRegionFromZones ([]string {zone })
64
+ testRegionalID = fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , project , region , name )
65
+ testSnapshotID = fmt .Sprintf ("projects/%s/global/snapshots/%s" , project , name )
67
66
)
68
67
69
68
func TestCreateSnapshotArguments (t * testing.T ) {
@@ -76,6 +75,7 @@ func TestCreateSnapshotArguments(t *testing.T) {
76
75
testCases := []struct {
77
76
name string
78
77
req * csi.CreateSnapshotRequest
78
+ seedDisks []* gce.CloudDisk
79
79
expSnapshot * csi.Snapshot
80
80
expErrCode codes.Code
81
81
}{
@@ -85,6 +85,9 @@ func TestCreateSnapshotArguments(t *testing.T) {
85
85
Name : name ,
86
86
SourceVolumeId : testVolumeID ,
87
87
},
88
+ seedDisks : []* gce.CloudDisk {
89
+ createZonalCloudDisk (name ),
90
+ },
88
91
expSnapshot : & csi.Snapshot {
89
92
SnapshotId : testSnapshotID ,
90
93
SourceVolumeId : testVolumeID ,
@@ -110,19 +113,27 @@ func TestCreateSnapshotArguments(t *testing.T) {
110
113
expErrCode : codes .InvalidArgument ,
111
114
},
112
115
{
113
- name : "fail wrong source volume" ,
116
+ name : "fail not found source volume" ,
114
117
req : & csi.CreateSnapshotRequest {
115
118
Name : name ,
116
- SourceVolumeId : "/test/wrongname" ,
119
+ SourceVolumeId : common . CreateZonalVolumeID ( project , zone , "non-exist-vol-name" ) ,
117
120
},
118
121
expErrCode : codes .NotFound ,
119
122
},
123
+ {
124
+ name : "fail invalid source volume" ,
125
+ req : & csi.CreateSnapshotRequest {
126
+ Name : name ,
127
+ SourceVolumeId : "/test/wrongname" ,
128
+ },
129
+ expErrCode : codes .InvalidArgument ,
130
+ },
120
131
}
121
132
122
133
for _ , tc := range testCases {
123
134
t .Logf ("test case: %s" , tc .name )
124
135
// Setup new driver each time so no interference
125
- gceDriver := initGCEDriver (t , nil )
136
+ gceDriver := initGCEDriver (t , tc . seedDisks )
126
137
127
138
// Start Test
128
139
resp , err := gceDriver .cs .CreateSnapshot (context .Background (), tc .req )
@@ -210,44 +221,45 @@ func TestListSnapshotsArguments(t *testing.T) {
210
221
testCases := []struct {
211
222
name string
212
223
req * csi.ListSnapshotsRequest
213
- expSnapshots int
224
+ numSnapshots int
214
225
expErrCode codes.Code
215
226
}{
216
227
{
217
228
name : "valid" ,
218
229
req : & csi.ListSnapshotsRequest {
219
- SnapshotId : testSnapshotID ,
230
+ SnapshotId : testSnapshotID + "0" ,
220
231
},
221
- expSnapshots : 1 ,
232
+ numSnapshots : 1 ,
222
233
},
223
234
{
224
235
name : "invalid id" ,
225
236
req : & csi.ListSnapshotsRequest {
226
237
SnapshotId : testSnapshotID + "/foo" ,
227
238
},
228
- expSnapshots : 0 ,
239
+ numSnapshots : 0 ,
229
240
},
230
241
{
231
242
name : "no id" ,
232
243
req : & csi.ListSnapshotsRequest {
233
244
SnapshotId : "" ,
234
245
},
235
- expSnapshots : totalSnapshotsNumber + 1 ,
246
+ numSnapshots : 5 ,
236
247
},
237
248
}
238
249
239
250
for _ , tc := range testCases {
240
251
t .Logf ("test case: %s" , tc .name )
241
- // Setup new driver each time so no interference
242
- gceDriver := initGCEDriver (t , nil )
243
252
244
- createReq := & csi.CreateSnapshotRequest {
245
- Name : name ,
246
- SourceVolumeId : testVolumeID ,
253
+ disks := []* gce.CloudDisk {}
254
+ for i := 0 ; i < tc .numSnapshots ; i ++ {
255
+ sname := fmt .Sprintf ("%s%d" , name , i )
256
+ disks = append (disks , createZonalCloudDisk (sname ))
247
257
}
248
- gceDriver .cs .CreateSnapshot (context .Background (), createReq )
249
258
250
- for i := 0 ; i < totalSnapshotsNumber ; i ++ {
259
+ // Setup new driver each time so no interference
260
+ gceDriver := initGCEDriver (t , disks )
261
+
262
+ for i := 0 ; i < tc .numSnapshots ; i ++ {
251
263
volumeID := fmt .Sprintf ("%s%d" , testVolumeID , i )
252
264
nameID := fmt .Sprintf ("%s%d" , name , i )
253
265
createReq := & csi.CreateSnapshotRequest {
@@ -280,16 +292,16 @@ func TestListSnapshotsArguments(t *testing.T) {
280
292
// Make sure responses match
281
293
snapshots := resp .GetEntries ()
282
294
//expectsnapshots := expSnapshot.GetEntries()
283
- if (snapshots == nil || len (snapshots ) == 0 ) && tc .expSnapshots == 0 {
295
+ if (snapshots == nil || len (snapshots ) == 0 ) && tc .numSnapshots == 0 {
284
296
continue
285
297
}
286
298
287
299
if snapshots == nil || len (snapshots ) == 0 {
288
300
// If one is nil or empty but not both
289
- t .Fatalf ("Expected snapshots number %v, got no snapshot" , tc .expSnapshots )
301
+ t .Fatalf ("Expected snapshots number %v, got no snapshot" , tc .numSnapshots )
290
302
}
291
- if len (snapshots ) != tc .expSnapshots {
292
- errStr := fmt .Sprintf ("Expected snapshot: %#v\n to equal snapshot: %#v\n " , snapshots [0 ].Snapshot , tc .expSnapshots )
303
+ if len (snapshots ) != tc .numSnapshots {
304
+ errStr := fmt .Sprintf ("Expected snapshot: %#v\n to equal snapshot: %#v\n " , snapshots [0 ].Snapshot , tc .numSnapshots )
293
305
t .Errorf (errStr )
294
306
}
295
307
}
@@ -664,8 +676,6 @@ func TestCreateVolumeArguments(t *testing.T) {
664
676
// Setup new driver each time so no interference
665
677
gceDriver := initGCEDriver (t , nil )
666
678
667
- //gceDriver.cs.CloudProvider.CreateSnapshot(context.Background, )
668
-
669
679
// Start Test
670
680
resp , err := gceDriver .cs .CreateVolume (context .Background (), tc .req )
671
681
//check response
@@ -731,8 +741,6 @@ func TestCreateVolumeWithVolumeSource(t *testing.T) {
731
741
// Setup new driver each time so no interference
732
742
gceDriver := initGCEDriver (t , nil )
733
743
734
- //gceDriver.cs.CloudProvider.CreateSnapshot(context.Background, )
735
-
736
744
// Start Test
737
745
req := & csi.CreateVolumeRequest {
738
746
Name : "test-name" ,
@@ -857,14 +865,14 @@ func TestDeleteVolume(t *testing.T) {
857
865
expErr : false ,
858
866
},
859
867
{
860
- name : "non-repairable ID" ,
868
+ name : "non-repairable ID (invalid) " ,
861
869
seedDisks : []* gce.CloudDisk {
862
870
createZonalCloudDisk ("nottherightname" ),
863
871
},
864
872
req : & csi.DeleteVolumeRequest {
865
873
VolumeId : common .GenerateUnderspecifiedVolumeID (name , true /* isZonal */ ),
866
874
},
867
- expErr : true ,
875
+ expErr : false ,
868
876
},
869
877
}
870
878
for _ , tc := range testCases {
@@ -1416,7 +1424,10 @@ func TestPickRandAndConsecutive(t *testing.T) {
1416
1424
1417
1425
func TestVolumeOperationConcurrency (t * testing.T ) {
1418
1426
readyToExecute := make (chan chan struct {}, 1 )
1419
- gceDriver := initBlockingGCEDriver (t , nil , readyToExecute )
1427
+ gceDriver := initBlockingGCEDriver (t , []* gce.CloudDisk {
1428
+ createZonalCloudDisk (name + "1" ),
1429
+ createZonalCloudDisk (name + "2" ),
1430
+ }, readyToExecute )
1420
1431
cs := gceDriver .cs
1421
1432
1422
1433
vol1CreateSnapshotAReq := & csi.CreateSnapshotRequest {
0 commit comments