Skip to content

Commit

Permalink
Fix golangci-lint warnings in snapshot_policy and storagepool
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshaySainiDell committed Mar 13, 2024
1 parent 14c7cdf commit 2075970
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
36 changes: 18 additions & 18 deletions snapshot_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
)

// CreateSnapshotPolicy creates a snapshot policy on the PowerFlex array
func (system *System) CreateSnapshotPolicy(snapPolicy *types.SnapshotPolicyCreateParam) (string, error) {
func (s *System) CreateSnapshotPolicy(snapPolicy *types.SnapshotPolicyCreateParam) (string, error) {
defer TimeSpent("crate snapshot policy", time.Now())

path := fmt.Sprintf("/api/types/SnapshotPolicy/instances")
snapResp := types.SnapShotPolicyCreateResp{}
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, snapPolicy, &snapResp)
if err != nil {
return "", err
Expand All @@ -35,10 +35,10 @@ func (system *System) CreateSnapshotPolicy(snapPolicy *types.SnapshotPolicyCreat
}

// RemoveSnapshotPolicy removes a snapshot policy from the PowerFlex array
func (system *System) RemoveSnapshotPolicy(id string) error {
func (s *System) RemoveSnapshotPolicy(id string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/removeSnapshotPolicy", id)
removeParam := &types.EmptyPayload{}
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, removeParam, nil)
if err != nil {
return err
Expand All @@ -47,12 +47,12 @@ func (system *System) RemoveSnapshotPolicy(id string) error {
}

// RenameSnapshotPolicy renames a snapshot policy
func (system *System) RenameSnapshotPolicy(id, name string) error {
func (s *System) RenameSnapshotPolicy(id, name string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/renameSnapshotPolicy", id)
renameSnap := &types.SnapshotPolicyRenameParam{
NewName: name,
}
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, renameSnap, nil)
if err != nil {
return err
Expand All @@ -61,9 +61,9 @@ func (system *System) RenameSnapshotPolicy(id, name string) error {
}

// ModifySnapshotPolicy modifies a snapshot policy
func (system *System) ModifySnapshotPolicy(modifysnapPolicy *types.SnapshotPolicyModifyParam, id string) error {
func (s *System) ModifySnapshotPolicy(modifysnapPolicy *types.SnapshotPolicyModifyParam, id string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/modifySnapshotPolicy", id)
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, modifysnapPolicy, nil)
if err != nil {
return err
Expand All @@ -72,9 +72,9 @@ func (system *System) ModifySnapshotPolicy(modifysnapPolicy *types.SnapshotPolic
}

// AssignVolumeToSnapshotPolicy assigns volume to a snapshot policy
func (system *System) AssignVolumeToSnapshotPolicy(assignVoltoSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error {
func (s *System) AssignVolumeToSnapshotPolicy(assignVoltoSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/addSourceVolumeToSnapshotPolicy", id)
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, assignVoltoSnap, nil)
if err != nil {
return err
Expand All @@ -83,9 +83,9 @@ func (system *System) AssignVolumeToSnapshotPolicy(assignVoltoSnap *types.Assign
}

// UnassignVolumeFromSnapshotPolicy unassigns volume from a snapshot policy
func (system *System) UnassignVolumeFromSnapshotPolicy(UnassignVolFromSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error {
func (s *System) UnassignVolumeFromSnapshotPolicy(UnassignVolFromSnap *types.AssignVolumeToSnapshotPolicyParam, id string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/removeSourceVolumeFromSnapshotPolicy", id)
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, UnassignVolFromSnap, nil)
if err != nil {
return err
Expand All @@ -94,10 +94,10 @@ func (system *System) UnassignVolumeFromSnapshotPolicy(UnassignVolFromSnap *type
}

// PauseSnapshotPolicy pause a snapshot policy
func (system *System) PauseSnapshotPolicy(id string) error {
func (s *System) PauseSnapshotPolicy(id string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/pauseSnapshotPolicy", id)
pauseParam := &types.EmptyPayload{}
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, pauseParam, nil)
if err != nil {
return err
Expand All @@ -106,10 +106,10 @@ func (system *System) PauseSnapshotPolicy(id string) error {
}

// ResumeSnapshotPolicy resume a snapshot policy which was paused
func (system *System) ResumeSnapshotPolicy(id string) error {
func (s *System) ResumeSnapshotPolicy(id string) error {
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/action/resumeSnapshotPolicy", id)
resumeParam := &types.EmptyPayload{}
err := system.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodPost, path, resumeParam, nil)
if err != nil {
return err
Expand All @@ -118,10 +118,10 @@ func (system *System) ResumeSnapshotPolicy(id string) error {
}

// GetSourceVolume returns a list of volumes assigned to snapshot policy
func (system *System) GetSourceVolume(id string) ([]*types.Volume, error) {
func (s *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(
err := s.client.getJSONWithRetry(
http.MethodGet, path, nil, &volumes)
if err != nil {
return nil, err
Expand Down
60 changes: 30 additions & 30 deletions snapshot_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func TestCreateSnapshotPolicy(t *testing.T) {
NumOfRetainedSnapshotsPerLevel: []string{"1"},
SnapshotAccessMode: "Invalid",
},
expected: errors.New("accessMode should get one of the following values: ReadWrite, ReadOnly, but its value is Invalid."),
expected: errors.New("accessMode should get one of the following values: ReadWrite, ReadOnly, but its value is Invalid"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -96,16 +96,16 @@ func TestModifySnapshotPolicyName(t *testing.T) {
{
id: "1234",
name: "renameSnapshotPolicy",
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -149,16 +149,16 @@ func TestModifySnapshotPolicy(t *testing.T) {
AutoSnapshotCreationCadenceInMin: "6",
NumOfRetainedSnapshotsPerLevel: []string{"2", "3"},
},
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -201,23 +201,23 @@ func TestAssignSnapshotPolicy(t *testing.T) {
snap: &types.AssignVolumeToSnapshotPolicyParam{
SourceVolumeID: "edba1bff00000001",
},
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
{
id: ID2,
snap: &types.AssignVolumeToSnapshotPolicyParam{
SourceVolumeID: "edba1bff000000",
},
expected: errors.New("Invalid volume. Please try again with a valid ID or name."),
expected: errors.New("Invalid volume. Please try again with a valid ID or name"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -262,32 +262,32 @@ func TestUnassignSnapshotPolicy(t *testing.T) {
SourceVolumeID: "edba1bff00000001",
AutoSnapshotRemovalAction: "Remove",
},
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
{
id: ID2,
snap: &types.AssignVolumeToSnapshotPolicyParam{
SourceVolumeID: "edba1bff000000",
AutoSnapshotRemovalAction: "Remove",
},
expected: errors.New("Invalid volume. Please try again with a valid ID or name."),
expected: errors.New("Invalid volume. Please try again with a valid ID or name"),
},
{
id: ID2,
snap: &types.AssignVolumeToSnapshotPolicyParam{
SourceVolumeID: "edba1bff000000",
AutoSnapshotRemovalAction: "Invalid",
},
expected: errors.New("autoSnapshotRemovalAction should get one of the following values: Remove, Detach, but its value is Invalid."),
expected: errors.New("autoSnapshotRemovalAction should get one of the following values: Remove, Detach, but its value is Invalid"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -323,16 +323,16 @@ func TestPauseSnapshotPolicy(t *testing.T) {
},
{
id: "Invalid",
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -368,16 +368,16 @@ func TestResumeSnapshotPolicy(t *testing.T) {
},
{
id: "Invalid",
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -413,16 +413,16 @@ func TestDeleteSnapshotPolicy(t *testing.T) {
},
{
id: "Invalid",
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -458,16 +458,16 @@ func TestGetSourceVolume(t *testing.T) {
},
{
id: "Invalid",
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)"),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
svr := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
t.Run("", func(_ *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions storagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ func (sp *StoragePool) GetSDSStoragePool() ([]types.Sds, error) {
}

// GetStoragePoolByID returns a Storagepool by ID
func (sys *System) GetStoragePoolByID(id string) (*types.StoragePool, error) {
func (s *System) GetStoragePoolByID(id string) (*types.StoragePool, error) {
defer TimeSpent("GetStoragePoolByID", time.Now())

path := fmt.Sprintf("/api/instances/StoragePool::%s", id)

var storagepool *types.StoragePool
err := sys.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodGet, path, nil, &storagepool)
if err != nil {
return nil, err
Expand All @@ -435,12 +435,12 @@ func (sys *System) GetStoragePoolByID(id string) (*types.StoragePool, error) {
}

// GetAllStoragePools returns all Storage pools on the system
func (sys *System) GetAllStoragePools() ([]types.StoragePool, error) {
func (s *System) GetAllStoragePools() ([]types.StoragePool, error) {
defer TimeSpent("GetStoragepool", time.Now())
path := "/api/types/StoragePool/instances"

var storagepools []types.StoragePool
err := sys.client.getJSONWithRetry(
err := s.client.getJSONWithRetry(
http.MethodGet, path, nil, &storagepools)
if err != nil {
return nil, err
Expand Down

0 comments on commit 2075970

Please sign in to comment.