Skip to content

Commit

Permalink
added one more function to retrive source volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnikaAgiwal2711 committed Jan 30, 2024
1 parent 0e42f2d commit a96ea69
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions inttests/snapshot_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
12 changes: 12 additions & 0 deletions snapshot_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
45 changes: 45 additions & 0 deletions snapshot_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
})
}
}
1 change: 0 additions & 1 deletion template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a96ea69

Please sign in to comment.