Skip to content

Commit

Permalink
If passed an empty volume name, VolumeExists should return false and …
Browse files Browse the repository at this point in the history
…not error (#1458)
  • Loading branch information
ntap-rippy authored Sep 20, 2023
1 parent 6e98a01 commit 35298b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions storage_drivers/ontap/api/ontap_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ func (c RestClient) getAllVolumesByPatternStyleAndState(

// checkVolumeExistsByNameAndStyle tests for the existence of a volume of the style and name specified
func (c RestClient) checkVolumeExistsByNameAndStyle(ctx context.Context, volumeName, style string) (bool, error) {
if volumeName == "" {
return false, nil
}
volume, err := c.getVolumeByNameAndStyle(ctx, volumeName, style)
if err != nil {
return false, err
Expand Down
12 changes: 12 additions & 0 deletions storage_drivers/ontap/api/ontap_rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4192,3 +4192,15 @@ func TestOntapRest_JobScheduleExists(t *testing.T) {
})
}
}

func TestOntapRest_VolumeExists(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(mockResourceNotFound))
defer server.Close()

rs := newRestClient(server.Listener.Addr().String(), server.Client())
assert.NotNil(t, rs)

volumeExists, err := rs.VolumeExists(ctx, "")
assert.NoError(t, err, "could not check if the volume exists")
assert.False(t, volumeExists)
}
4 changes: 4 additions & 0 deletions storage_drivers/ontap/api/ontap_zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,10 @@ func (c Client) VolumeSetQosPolicyGroupName(

// VolumeExists tests for the existence of a Flexvol
func (c Client) VolumeExists(ctx context.Context, name string) (bool, error) {
if name == "" {
return false, nil
}

response, err := azgo.NewVolumeSizeRequest().
SetVolume(name).
ExecuteUsing(c.zr)
Expand Down
10 changes: 10 additions & 0 deletions storage_drivers/ontap/api/ontap_zapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ func TestGetError(t *testing.T) {

assert.Equal(t, "unexpected nil ZAPI result", e.(azgo.ZapiError).Reason(), "Strings not equal")
}

func TestVolumeExists_EmptyVolumeName(t *testing.T) {
ctx := context.Background()

zapiClient := Client{}
volumeExists, err := zapiClient.VolumeExists(ctx, "")

assert.NoError(t, err, "VolumeExists should not have errored with a missing volume name")
assert.False(t, volumeExists)
}

0 comments on commit 35298b6

Please sign in to comment.