Skip to content

Commit d85c8a8

Browse files
committed
fix test with broken type in DoAndReturn
1 parent d81c51a commit d85c8a8

2 files changed

Lines changed: 51 additions & 35 deletions

File tree

pkg/csi/blockstorage/controllerserver_test.go

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,23 @@ var _ = Describe("ControllerServer test", Ordered, func() {
305305
Id: new("snapshot-volume-id"),
306306
AvailabilityZone: "eu01",
307307
}, nil)
308-
iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).
309-
Do(func(_ context.Context, opts *iaas.CreateVolumePayload) {
308+
iaasClient.EXPECT().
309+
CreateVolume(gomock.Any(), gomock.Any()).
310+
DoAndReturn(func(_ context.Context, opts *iaas.CreateVolumePayload) (*iaas.Volume, error) {
310311
Expect(opts.Source.Id).To(Equal("snapshot-id"))
311312
Expect(opts.Source.Type).To(Equal("snapshot"))
312-
}).
313-
Return(&iaas.Volume{
314-
Id: new("volume-id"),
315-
Name: new("new volume"),
316-
AvailabilityZone: "eu01",
317-
Size: new(int64(20)),
318-
}, nil)
313+
314+
volumeID := "volume-id"
315+
name := "new volume"
316+
size := int64(20)
317+
318+
return &iaas.Volume{
319+
Id: &volumeID,
320+
Name: &name,
321+
AvailabilityZone: "eu01",
322+
Size: &size,
323+
}, nil
324+
})
319325
iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil)
320326

321327
_, err := fakeCs.CreateVolume(context.Background(), req)
@@ -375,17 +381,23 @@ var _ = Describe("ControllerServer test", Ordered, func() {
375381
Status: new("AVAILABLE"),
376382
AvailabilityZone: new("eu01"),
377383
}, nil)
378-
iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).
379-
Do(func(_ context.Context, opts *iaas.CreateVolumePayload) {
384+
iaasClient.EXPECT().
385+
CreateVolume(gomock.Any(), gomock.Any()).
386+
DoAndReturn(func(_ context.Context, opts *iaas.CreateVolumePayload) (*iaas.Volume, error) {
380387
Expect(opts.Source.Id).To(Equal("snapshot-id"))
381388
Expect(opts.Source.Type).To(Equal("backup"))
382-
}).
383-
Return(&iaas.Volume{
384-
Id: new("volume-id"),
385-
Name: new("new volume"),
386-
AvailabilityZone: "eu01",
387-
Size: new(int64(20)),
388-
}, nil)
389+
390+
volumeID := "volume-id"
391+
name := "new volume"
392+
size := int64(20)
393+
394+
return &iaas.Volume{
395+
Id: &volumeID,
396+
Name: &name,
397+
AvailabilityZone: "eu01",
398+
Size: &size,
399+
}, nil
400+
})
389401
iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil)
390402

391403
_, err := fakeCs.CreateVolume(context.Background(), req)
@@ -484,17 +496,23 @@ var _ = Describe("ControllerServer test", Ordered, func() {
484496
Status: new("AVAILABLE"),
485497
AvailabilityZone: "eu01",
486498
}, nil)
487-
iaasClient.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).
488-
Do(func(_ context.Context, opts *iaas.CreateVolumePayload) {
499+
iaasClient.EXPECT().
500+
CreateVolume(gomock.Any(), gomock.Any()).
501+
DoAndReturn(func(_ context.Context, opts *iaas.CreateVolumePayload) (*iaas.Volume, error) {
489502
Expect(opts.Source.Id).To(Equal("volume-source-id"))
490503
Expect(opts.Source.Type).To(Equal("volume"))
491-
}).
492-
Return(&iaas.Volume{
493-
Id: new("volume-id"),
494-
Name: new("new volume"),
495-
AvailabilityZone: "eu01",
496-
Size: new(int64(20)),
497-
}, nil)
504+
505+
name := "new volume"
506+
volumeID := "volume-id"
507+
size := int64(20)
508+
509+
return &iaas.Volume{
510+
Id: &volumeID,
511+
Name: &name,
512+
AvailabilityZone: "eu01",
513+
Size: &size,
514+
}, nil
515+
})
498516
iaasClient.EXPECT().WaitVolumeTargetStatusWithCustomBackoff(gomock.Any(), "volume-id", gomock.Any(), gomock.Any()).Return(nil)
499517

500518
_, err := fakeCs.CreateVolume(context.Background(), req)

pkg/csi/blockstorage/sanity_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ var _ = Describe("CSI sanity test", Ordered, func() {
165165
).DoAndReturn(func(_ context.Context, payload *iaas.CreateSnapshotPayload) (*iaas.Snapshot, error) {
166166
newSnap := &iaas.Snapshot{
167167
Id: new(uuid.New().String()),
168-
Name: new(name),
168+
Name: payload.Name,
169169
Status: new(stackitclient.SnapshotReadyStatus),
170170
CreatedAt: new(time.Now()),
171171
Size: new(int64(10)), // 10 GiB
172-
VolumeId: volID,
172+
VolumeId: payload.VolumeId,
173173
}
174174
createdSnapshots[*newSnap.Id] = newSnap
175175
return newSnap, nil
176176
}).AnyTimes()
177177

178-
iaasClient.EXPECT().GetServer(
178+
iaasClient.EXPECT().GetSnapshot(
179179
gomock.Any(), // context
180180
gomock.Any(), // snapshotID
181181
).DoAndReturn(func(_ context.Context, snapshotID string) (*iaas.Snapshot, error) {
@@ -189,7 +189,7 @@ var _ = Describe("CSI sanity test", Ordered, func() {
189189
iaasClient.EXPECT().ListSnapshots(
190190
gomock.Any(), // context
191191
gomock.Any(), // filters
192-
).DoAndReturn(func(_ context.Context, filters map[string]string) ([]iaas.Snapshot, string, error) {
192+
).DoAndReturn(func(_ context.Context, filters map[string]string) ([]iaas.Snapshot, error) {
193193
var snapshots []iaas.Snapshot
194194

195195
markerFilter := filters["Marker"]
@@ -223,16 +223,14 @@ var _ = Describe("CSI sanity test", Ordered, func() {
223223
}
224224
}
225225

226-
retToken := ""
227226
if limitFilter != "" {
228227
limit, _ := strconv.Atoi(limitFilter)
229228

230229
if limit > 0 && limit <= len(snapshots) {
231230
snapshots = snapshots[:limit]
232231
}
233-
retToken = limitFilter
234232
}
235-
return snapshots, retToken, nil
233+
return snapshots, nil
236234
}).AnyTimes()
237235

238236
iaasClient.EXPECT().DeleteSnapshot(
@@ -323,7 +321,7 @@ var _ = Describe("CSI sanity test", Ordered, func() {
323321
gomock.Any(), // instanceID
324322
gomock.Any(), // volumeID
325323
gomock.Any(), // payload
326-
).DoAndReturn(func(_ context.Context, instanceID string, volumeID string) (string, error) {
324+
).DoAndReturn(func(_ context.Context, instanceID string, volumeID string, _ iaas.AddVolumeToServerPayload) (string, error) {
327325
vol, ok := createdVolumes[volumeID]
328326
if !ok {
329327
return "", &oapierror.GenericOpenAPIError{StatusCode: http.StatusNotFound}

0 commit comments

Comments
 (0)