Skip to content

Commit

Permalink
Some more validation and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 committed Dec 18, 2023
1 parent c8ee37f commit dafa62a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ecs-init/volumes/ecs_volume_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func (a *AmazonECSVolumePlugin) Mount(r *volume.MountRequest) (*volume.MountResp
seelog.Infof("Received mount request %+v", r)

// Validate the request
if len(r.Name) == 0 {
return nil, fmt.Errorf("no volume in the request")
}
if len(r.ID) == 0 {
return nil, fmt.Errorf("no mount ID in the request")
}
Expand Down Expand Up @@ -254,6 +257,9 @@ func (a *AmazonECSVolumePlugin) Unmount(r *volume.UnmountRequest) error {
seelog.Infof("Received unmount request %+v", r)

// Validate the request
if len(r.Name) == 0 {
return fmt.Errorf("no volume in the request")
}
if len(r.ID) == 0 {
return fmt.Errorf("no mount ID in the request")
}
Expand Down
10 changes: 10 additions & 0 deletions ecs-init/volumes/ecs_volume_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,11 @@ func TestPluginMount(t *testing.T) {
req: &volume.MountRequest{Name: volName},
expectedError: "no mount ID in the request",
},
{
name: "no volume in the request",
req: &volume.MountRequest{},
expectedError: "no volume in the request",
},
{
name: "driver fails to mount",
setDriverExpectations: func(d *mock_driver.MockVolumeDriver) {
Expand Down Expand Up @@ -1005,6 +1010,11 @@ func TestPluginUnmount(t *testing.T) {
req: &volume.UnmountRequest{Name: volName},
expectedError: "no mount ID in the request",
},
{
name: "no volume in the request",
req: &volume.UnmountRequest{},
expectedError: "no volume in the request",
},
{
name: "driver fails to unmount",
setDriverExpectations: func(d *mock_driver.MockVolumeDriver) {
Expand Down

0 comments on commit dafa62a

Please sign in to comment.