Skip to content

Commit

Permalink
fix ut for shared block
Browse files Browse the repository at this point in the history
Signed-off-by: sulakshm <[email protected]>
  • Loading branch information
sulakshm committed Aug 28, 2024
1 parent df65799 commit f521d58
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions csi/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@ func TestControllerCreateVolumeBlock(t *testing.T) {
assert.NotEqual(t, "true", volumeInfo.GetVolumeContext()[api.SpecSharedv4])
}

func TestControllerCreateVolumeBlockSharedInvalid(t *testing.T) {
func TestControllerCreateVolumeBlockSharedValid(t *testing.T) {
// Create server and client connection
s := newTestServer(t)
defer s.Stop()
Expand All @@ -2568,8 +2568,6 @@ func TestControllerCreateVolumeBlockSharedInvalid(t *testing.T) {
AccessType: &csi.VolumeCapability_Block{
Block: &csi.VolumeCapability_BlockVolume{},
},
},
{
AccessMode: &csi.VolumeCapability_AccessMode{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
Expand All @@ -2579,13 +2577,60 @@ func TestControllerCreateVolumeBlockSharedInvalid(t *testing.T) {
RequiredBytes: size,
},
Secrets: secretsMap,
Parameters: map[string]string{
api.SpecSharedBlock: "true",
},
}

// Setup mock functions
_, err := c.CreateVolume(context.Background(), req)
assert.Error(t, err)
assert.Contains(t, err.Error(), "Shared raw block volumes are not supported")
id := "myid"
gomock.InOrder(
s.MockDriver().
EXPECT().
Inspect([]string{name}).
Return(nil, fmt.Errorf("not found")).
Times(1),

s.MockDriver().
EXPECT().
Enumerate(&api.VolumeLocator{Name: name}, nil).
Return(nil, fmt.Errorf("not found")).
Times(1),

s.MockDriver().
EXPECT().
Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(id, nil).
Times(1),

s.MockDriver().
EXPECT().
Enumerate(&api.VolumeLocator{VolumeIds: []string{id}}, nil).
Return([]*api.Volume{
{
Id: id,
Locator: &api.VolumeLocator{
Name: name,
VolumeLabels: secretsMap,
},
Spec: &api.VolumeSpec{
Size: uint64(size),
SharedBlock: true,
},
},
}, nil).
Times(1),
)

r, err := c.CreateVolume(context.Background(), req)
assert.Nil(t, err)
assert.NotNil(t, r)
volumeInfo := r.GetVolume()

assert.Equal(t, id, volumeInfo.GetVolumeId())
assert.Equal(t, size, volumeInfo.GetCapacityBytes())
assert.Equal(t, "true", volumeInfo.GetVolumeContext()[api.SpecSharedBlock])
assert.NotEqual(t, "true", volumeInfo.GetVolumeContext()[api.SpecSharedv4])
}

func TestControllerCreateVolumeWithoutTopology(t *testing.T) {
Expand Down

0 comments on commit f521d58

Please sign in to comment.