Skip to content

Commit

Permalink
Merge pull request #22 from prankulmahajan/profile-empty
Browse files Browse the repository at this point in the history
Add condition for empty profile
  • Loading branch information
prankulmahajan authored Aug 3, 2021
2 parents e6c9365 + e87380c commit 0274b5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions block/provider/create_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func validateVolumeRequest(volumeRequest provider.Volume) (models.ResourceGroup,
if volumeRequest.Iops != nil {
iops = ToInt64(*volumeRequest.Iops)
}
if volumeRequest.VPCVolume.Profile == nil {
return resourceGroup, iops, userError.GetUserError("VolumeProfileEmpty", nil)
}
if volumeRequest.VPCVolume.Profile.Name != customProfile && iops > 0 {
return resourceGroup, iops, userError.GetUserError("VolumeProfileIopsInvalid", nil)
}
Expand Down
14 changes: 14 additions & 0 deletions block/provider/create_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ func TestCreateVolume(t *testing.T) {
assert.Nil(t, volumeResponse)
assert.NotNil(t, err)
},
}, {
testCaseName: "Volume with empty profile",
profileName: "",
providerVolume: provider.Volume{
VolumeID: "16f293bf-test-4bff-816f-e199c0c65db5",
Name: String("test-volume-name"),
Capacity: Int(10),
Iops: String("1000"),
VPCVolume: provider.VPCVolume{},
},
verify: func(t *testing.T, volumeResponse *provider.Volume, err error) {
assert.Nil(t, volumeResponse)
assert.NotNil(t, err)
},
}, {
testCaseName: "Volume with no validation issues",
profileName: "general-purpose",
Expand Down
7 changes: 7 additions & 0 deletions common/messages/messages_en.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ var messagesEn = map[string]util.Message{
RC: 400,
Action: "Review available volume profiles and IOPS in the IBM Cloud Block Storage for VPC documentation https://cloud.ibm.com/docs/vpc-on-classic-block-storage?topic=vpc-on-classic-block-storage-block-storage-profiles.",
},
"VolumeProfileEmpty": {
Code: "VolumeProfileEmpty",
Description: "Volume profile is empty, you need to pass valid profile name.",
Type: util.InvalidRequest,
RC: 400,
Action: "Review storage class used to create volume and add valid profile parameter.",
},
"EmptyResourceGroup": {
Code: "EmptyResourceGroup",
Description: "Resource group information could not be found.",
Expand Down

0 comments on commit 0274b5e

Please sign in to comment.