diff --git a/inttests/snapshot_policy_test.go b/inttests/snapshot_policy_test.go index 401f5d8..fb5aeb7 100644 --- a/inttests/snapshot_policy_test.go +++ b/inttests/snapshot_policy_test.go @@ -65,6 +65,10 @@ func TestCreateModifyDeleteSnapshotPolicy(t *testing.T) { err = system.AssignVolumeToSnapshotPolicy(assignVolume, snapID) assert.Nil(t, err) + vol, err2 := system.GetSourceVolume(snapID) + assert.Nil(t, err2) + assert.NotNil(t, vol) + assignVolume = &types.AssignVolumeToSnapshotPolicyParam{ SourceVolumeId: "Invalid", } diff --git a/snapshot_policy.go b/snapshot_policy.go index 086711f..eaa04ba 100644 --- a/snapshot_policy.go +++ b/snapshot_policy.go @@ -116,3 +116,15 @@ func (system *System) ResumeSnapshotPolicy(id string) error { } return nil } + +// GetSourceVolume returns a list of volumes assigned to snapshot policy +func (system *System) GetSourceVolume(id string) ([]*types.Volume, error) { + var volumes []*types.Volume + path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/relationships/SourceVolume", id) + err := system.client.getJSONWithRetry( + http.MethodGet, path, nil, &volumes) + if err != nil { + return nil, err + } + return volumes, nil +} diff --git a/snapshot_policy_test.go b/snapshot_policy_test.go index 93ac141..a41cbd9 100644 --- a/snapshot_policy_test.go +++ b/snapshot_policy_test.go @@ -446,3 +446,48 @@ func TestDeleteSnapshotPolicy(t *testing.T) { }) } } + +func TestGetSourceVolume(t *testing.T) { + type testCase struct { + id string + expected error + } + cases := []testCase{ + { + id: ID2, + expected: nil, + }, + { + id: "Invalid", + expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."), + }, + } + svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + })) + defer svr.Close() + + for _, tc := range cases { + tc := tc + t.Run("", func(ts *testing.T) { + client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false) + if err != nil { + t.Fatal(err) + } + + s := System{ + client: client, + } + + _, err2 := s.GetSourceVolume(tc.id) + if err2 != nil { + if tc.expected == nil { + t.Errorf("Assigning volume to snapshot policy did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected) + } else { + if err2.Error() != tc.expected.Error() { + t.Errorf("Assigning volume to snapshot policy did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected) + } + } + } + }) + } +} diff --git a/template_test.go b/template_test.go index eb3a73f..e7a5159 100644 --- a/template_test.go +++ b/template_test.go @@ -118,7 +118,6 @@ func TestGetTemplateByIDNegative(t *testing.T) { assert.NotNil(t, err) } - func TestGetTemplateByFiltersNegative(t *testing.T) { svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) diff --git a/types/v1/types.go b/types/v1/types.go index 0a9fbfa..548291d 100644 --- a/types/v1/types.go +++ b/types/v1/types.go @@ -1086,7 +1086,7 @@ type SnapshotPolicy struct { Links []*Link `json:"links"` } -// SnapshotPolicyCreate defines the struct for creating a Snapshot Policy +// SnapshotPolicyCreateParam defines the struct for creating a Snapshot Policy type SnapshotPolicyCreateParam struct { AutoSnapshotCreationCadenceInMin string `json:"autoSnapshotCreationCadenceInMin"` NumOfRetainedSnapshotsPerLevel []string `json:"numOfRetainedSnapshotsPerLevel"`