util: add helper to get pvcnamespace from input

added helper function to return the pvc namespace
name from the input parameters.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2022-03-16 19:19:06 +05:30
committed by mergify[bot]
parent 772fe8d6c8
commit 366c2ace31
2 changed files with 39 additions and 0 deletions

View File

@ -60,3 +60,36 @@ func TestRemoveCSIPrefixedParameters(t *testing.T) {
})
}
}
func TestGetOwner(t *testing.T) {
t.Parallel()
tests := []struct {
name string
args map[string]string
want string
}{
{
name: "namespace is not present in the parameters",
args: map[string]string{
"foo": "bar",
},
want: "",
},
{
name: "namespace is present in the parameters",
args: map[string]string{
"csi.storage.k8s.io/pvc/namespace": "bar",
},
want: "bar",
},
}
for _, tt := range tests {
ts := tt
t.Run(ts.name, func(t *testing.T) {
t.Parallel()
if got := GetOwner(ts.args); got != ts.want {
t.Errorf("GetOwner() = %v, want %v", got, ts.want)
}
})
}
}