This repository has been archived by the owner on Aug 14, 2021. It is now read-only.
forked from kubernetes-retired/external-storage
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieves the namespace from its VolumeSnapshotRef name instead of 'P…
…ersistentVolumeRef.Namespace'. (#43) * Retrieves the namespace from its VolumeSnapshotRef name Retrieves the volume namespace and the short name of a snapshot from its 'VolumeSnapshotRef.Name', instead of 'PersistentVolumeRef.Namespace'. exmaple SnapshotRef - "test-ns/snap1" Change required b/c 'PersistentVolumeRef.Namespace contains' nil value * Add unit test for namespace extract logic from unique name Signed-off-by: prateekpandey14 <[email protected]>
- Loading branch information
1 parent
87e79f8
commit c742c31
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package openebs | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetNameAndNameSpaceFromSnapshoName(t *testing.T) { | ||
cases := map[string]struct { | ||
name string | ||
expectErr error | ||
expectNamespace string | ||
expectSnapshotName string | ||
}{ | ||
|
||
"SnapshotName with Namespace": {"percona/fastfurious", nil, "percona", "fastfurious"}, | ||
"SnapshotName without Namespace": {"fastfurious", fmt.Errorf("invalid snapshot name"), "", ""}, | ||
"Invalid Unique SnapshotName": {"k8s/percona/fastfurious", fmt.Errorf("invalid snapshot name"), "", ""}, | ||
"Nil SnapshotName": {"", fmt.Errorf("invalid snapshot name"), "", ""}, | ||
} | ||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
namespace, snapshotName, err := GetNameAndNameSpaceFromSnapshotName(tc.name) | ||
|
||
if !reflect.DeepEqual(err, tc.expectErr) { | ||
t.Errorf("Expected %v, got %v", tc.expectErr, err) | ||
} | ||
if !reflect.DeepEqual(namespace, tc.expectNamespace) { | ||
t.Errorf("Expected %v, got %v", tc.expectNamespace, namespace) | ||
} | ||
if !reflect.DeepEqual(snapshotName, tc.expectSnapshotName) { | ||
t.Errorf("Expected %v, got %v", tc.expectSnapshotName, snapshotName) | ||
} | ||
}) | ||
} | ||
} |