Skip to content

Commit

Permalink
fix table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdutka-dell committed Feb 6, 2024
1 parent bcee455 commit 889cf95
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func ParseNormalizedSnapshotID(ctx context.Context, snapID string) (string, stri
log := GetRunIDLogger(ctx)
tokens := strings.Split(snapID, SnapshotIDSeparator)
if len(tokens) < 1 || snapID == "" {
return "", "", "", fmt.Errorf("snapshot ID '%s' cannot be split into tokens", snapID)
return "", "", "", fmt.Errorf("snapshot ID cannot be split into tokens")
}

snapshotID := tokens[0]
Expand Down
86 changes: 51 additions & 35 deletions common/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.

import (
"context"
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -83,41 +84,56 @@ func TestParseNormalizedVolumeID(t *testing.T) {

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

// snapID with id only
snapID, clusterName, accessZone, err := ParseNormalizedSnapshotID(ctx, "12345")
assert.Equal(t, "12345", snapID)
assert.Equal(t, "", clusterName)
assert.Equal(t, "", accessZone)
assert.Nil(t, err)

// snapID with id and cluster
snapID, clusterName, accessZone, err = ParseNormalizedSnapshotID(ctx, "12345=_=_=cluster1")
assert.Equal(t, "12345", snapID)
assert.Equal(t, "cluster1", clusterName)
assert.Equal(t, "", accessZone)
assert.Nil(t, err)

// snapID with id, cluster and zone
snapID, clusterName, accessZone, err = ParseNormalizedSnapshotID(ctx, "12345=_=_=cluster1=_=_=zone1")
assert.Equal(t, "12345", snapID)
assert.Equal(t, "cluster1", clusterName)
assert.Equal(t, "zone1", accessZone)
assert.Nil(t, err)

// snapID with id, cluster, zone and additional suffix
snapID, clusterName, accessZone, err = ParseNormalizedSnapshotID(ctx, "12345=_=_=cluster1=_=_=zone1=_=_=suffix")
assert.Equal(t, "12345", snapID)
assert.Equal(t, "cluster1", clusterName)
assert.Equal(t, "zone1", accessZone)
assert.Nil(t, err)

// empty snapID
snapID, clusterName, accessZone, err = ParseNormalizedSnapshotID(ctx, "")
assert.Equal(t, "", snapID)
assert.Equal(t, "", clusterName)
assert.Equal(t, "", accessZone)
assert.NotNil(t, err)
testCases := []struct {
input string
expectedSnapID string
expectedCluster string
expectedZone string
expectedErr error
}{
{
input: "12345",
expectedSnapID: "12345",
expectedCluster: "",
expectedZone: "",
expectedErr: nil,
},
{
input: "12345=_=_=cluster1",
expectedSnapID: "12345",
expectedCluster: "cluster1",
expectedZone: "",
expectedErr: nil,
},
{
input: "12345=_=_=cluster1=_=_=zone1",
expectedSnapID: "12345",
expectedCluster: "cluster1",
expectedZone: "zone1",
expectedErr: nil,
},
{
input: "12345=_=_=cluster1=_=_=zone1=_=_=suffix",
expectedSnapID: "12345",
expectedCluster: "cluster1",
expectedZone: "zone1",
expectedErr: nil,
},
{
input: "",
expectedSnapID: "",
expectedCluster: "",
expectedZone: "",
expectedErr: errors.New("snapshot ID cannot be split into tokens"),
},
}
for _, tc := range testCases {
snapID, clusterName, accessZone, err := ParseNormalizedSnapshotID(ctx, tc.input)
assert.Equal(t, tc.expectedSnapID, snapID)
assert.Equal(t, tc.expectedCluster, clusterName)
assert.Equal(t, tc.expectedZone, accessZone)
assert.Equal(t, tc.expectedErr, err)
}
}

func TestGetPathForVolume(t *testing.T) {
Expand Down

0 comments on commit 889cf95

Please sign in to comment.