Skip to content

Commit 2127817

Browse files
committed
test: WaitForVolumeLinodeID
1 parent 7c7a05e commit 2127817

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

internal/driver/controllerserver_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,49 @@ func TestControllerPublishVolume(t *testing.T) {
396396
},
397397
expectedError: errMaxVolumeAttachments(6),
398398
},
399+
{
400+
name: "publish fails when WaitForVolumeLinodeID times out",
401+
req: &csi.ControllerPublishVolumeRequest{
402+
VolumeId: "1008-testvol",
403+
NodeId: "2008",
404+
VolumeCapability: &csi.VolumeCapability{
405+
AccessType: &csi.VolumeCapability_Mount{
406+
Mount: &csi.VolumeCapability_MountVolume{},
407+
},
408+
AccessMode: &csi.VolumeCapability_AccessMode{
409+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
410+
},
411+
},
412+
VolumeContext: map[string]string{
413+
VolumeTopologyRegion: "us-east",
414+
},
415+
Readonly: false,
416+
},
417+
expectLinodeClientCalls: func(m *mocks.MockLinodeClient) {
418+
m.EXPECT().GetInstance(gomock.Any(), 2008).Return(&linodego.Instance{
419+
ID: 2008,
420+
Specs: &linodego.InstanceSpec{Memory: 16 << 10},
421+
}, nil)
422+
// Volume not attached
423+
m.EXPECT().GetVolume(gomock.Any(), 1008).Return(&linodego.Volume{
424+
ID: 1008,
425+
LinodeID: nil,
426+
Size: 10,
427+
Status: linodego.VolumeActive,
428+
}, nil)
429+
// checkAttachmentCapacity: can attach
430+
m.EXPECT().ListInstanceDisks(gomock.Any(), 2008, gomock.Any()).Return([]linodego.InstanceDisk{}, nil)
431+
m.EXPECT().ListInstanceVolumes(gomock.Any(), 2008, gomock.Any()).Return([]linodego.Volume{}, nil)
432+
// AttachVolume succeeds
433+
m.EXPECT().AttachVolume(gomock.Any(), 1008, gomock.Any()).Return(&linodego.Volume{
434+
ID: 1008,
435+
LinodeID: createLinodeID(2008),
436+
}, nil)
437+
// WaitForVolumeLinodeID fails (timeout)
438+
m.EXPECT().WaitForVolumeLinodeID(gomock.Any(), 1008, gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("timed out waiting for volume attachment"))
439+
},
440+
expectedError: fmt.Errorf("timed out waiting for volume attachment"),
441+
},
399442
}
400443
for _, tt := range tests {
401444
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)