Skip to content

Commit

Permalink
Fix bug where len is compared to less than 0 (#1682)
Browse files Browse the repository at this point in the history
* Fix bug where len is less than 0

* unit tests for errors
  • Loading branch information
bathina2 committed Feb 16, 2023
1 parent cc44fa3 commit 0db8d22
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/blockstorage/ibm/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ func (s *ibmCloud) volumeParse(ctx context.Context, vol *ibmprov.Volume) (*block
}
attribs[LunIDAttName] = vol.LunID

// TODO: Fix issue where we don't catch the error uf vol.IscsiTargetIPAddresses is empty
// Related ticket - https://github.com/kanisterio/kanister/issues/1683
if len(vol.IscsiTargetIPAddresses) < 0 { //nolint:staticcheck
if len(vol.IscsiTargetIPAddresses) == 0 {
return nil, errors.New("IscsiTargetIPAddresses are missing from Volume info")
}
if len(vol.Attributes) > 0 {
Expand Down
59 changes: 59 additions & 0 deletions pkg/blockstorage/ibm/ibmcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"
"time"

"github.com/IBM/ibmcloud-storage-volume-lib/config"
ibmprov "github.com/IBM/ibmcloud-storage-volume-lib/lib/provider"
"github.com/luci/go-render/render"
. "gopkg.in/check.v1"
Expand Down Expand Up @@ -142,3 +143,61 @@ func (s TestIBMCloud) TestVolRestore(c *C) {
err = s.provider.VolumeDelete(context.Background(), resVol)
c.Assert(err, IsNil)
}

type TestIBMCloudLocal struct{}

var _ = Suite(&TestIBMCloudLocal{})

func (s TestIBMCloudLocal) TestVolParse(c *C) {
ctx := context.Background()
capInt := 1
for _, tc := range []struct {
vol *ibmprov.Volume
err Checker
}{
{
vol: &ibmprov.Volume{
LunID: "lun",
IscsiTargetIPAddresses: []string{"target"},
Attributes: map[string]string{
"key": "value",
},
Capacity: &capInt,
},
err: IsNil,
},
{
vol: &ibmprov.Volume{
LunID: "lun",
IscsiTargetIPAddresses: []string{},
Attributes: map[string]string{
"key": "value",
},
Capacity: &capInt,
},
err: NotNil,
},
{
vol: &ibmprov.Volume{
LunID: "",
Provider: "slbpname",
IscsiTargetIPAddresses: []string{},
Attributes: map[string]string{
"key": "value",
},
Capacity: &capInt,
},
err: NotNil,
},
} {
ic := &ibmCloud{
cli: &client{
SLCfg: config.SoftlayerConfig{
SoftlayerBlockProviderName: "slbpname",
},
},
}
_, err := ic.volumeParse(ctx, tc.vol)
c.Assert(err, tc.err)
}
}

0 comments on commit 0db8d22

Please sign in to comment.