Merge pull request #60836 from hanxiaoshuai/addut03061

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

add unit test for function ParseKindArg and ParseGroupKind

**What this PR does / why we need it**:
add unit test for function ParseKindArg and ParseGroupKind
**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-03-24 11:38:03 -07:00 committed by GitHub
commit c4eac55ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -134,3 +134,47 @@ func TestKindForGroupVersionKinds(t *testing.T) {
}
}
}
func TestParseKindArg(t *testing.T) {
tests := []struct {
input string
gvk *GroupVersionKind
gk GroupKind
}{
{input: "Pod", gk: GroupKind{Kind: "Pod"}},
{input: ".apps", gk: GroupKind{Group: "apps"}},
{input: "Pod.", gk: GroupKind{Kind: "Pod"}},
{input: "StatefulSet.apps", gk: GroupKind{Group: "apps", Kind: "StatefulSet"}},
{input: "StatefulSet.v1.apps", gvk: &GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}, gk: GroupKind{Group: "v1.apps", Kind: "StatefulSet"}},
}
for i, test := range tests {
t.Run(test.input, func(t *testing.T) {
gvk, gk := ParseKindArg(test.input)
if (gvk != nil && test.gvk == nil) || (gvk == nil && test.gvk != nil) || (test.gvk != nil && *gvk != *test.gvk) {
t.Errorf("%d: expected output: %#v, got: %#v", i, test.gvk, gvk)
}
if gk != test.gk {
t.Errorf("%d: expected output: %#v, got: %#v", i, test.gk, gk)
}
})
}
}
func TestParseGroupKind(t *testing.T) {
tests := []struct {
input string
out GroupKind
}{
{input: "Pod", out: GroupKind{Kind: "Pod"}},
{input: ".StatefulSet", out: GroupKind{Group: "StatefulSet"}},
{input: "StatefulSet.apps", out: GroupKind{Group: "apps", Kind: "StatefulSet"}},
}
for i, test := range tests {
t.Run(test.input, func(t *testing.T) {
out := ParseGroupKind(test.input)
if out != test.out {
t.Errorf("%d: expected output: %#v, got: %#v", i, test.out, out)
}
})
}
}