New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Match GroupVersionKind against specific version #34010
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,3 +147,47 @@ func TestGroupVersionMarshalJSON(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestKindForGroupVersionKinds(t *testing.T) { | ||
gvks := GroupVersions{ | ||
GroupVersion{Group: "batch", Version: "v1"}, | ||
GroupVersion{Group: "batch", Version: "v2alpha1"}, | ||
GroupVersion{Group: "policy", Version: "v1alpha1"}, | ||
} | ||
cases := []struct { | ||
input []GroupVersionKind | ||
target GroupVersionKind | ||
ok bool | ||
}{ | ||
{ | ||
input: []GroupVersionKind{{Group: "batch", Version: "v2alpha1", Kind: "ScheduledJob"}}, | ||
target: GroupVersionKind{Group: "batch", Version: "v2alpha1", Kind: "ScheduledJob"}, | ||
ok: true, | ||
}, | ||
{ | ||
input: []GroupVersionKind{{Group: "batch", Version: "v3alpha1", Kind: "CronJob"}}, | ||
target: GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"}, | ||
ok: true, | ||
}, | ||
{ | ||
input: []GroupVersionKind{{Group: "policy", Version: "v1alpha1", Kind: "PodDisruptionBudget"}}, | ||
target: GroupVersionKind{Group: "policy", Version: "v1alpha1", Kind: "PodDisruptionBudget"}, | ||
ok: true, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add all the other scenarios to this test. |
||
{ | ||
input: []GroupVersionKind{{Group: "apps", Version: "v1alpha1", Kind: "PetSet"}}, | ||
target: GroupVersionKind{}, | ||
ok: false, | ||
}, | ||
} | ||
|
||
for i, c := range cases { | ||
target, ok := gvks.KindForGroupVersionKinds(c.input) | ||
if c.target != target { | ||
t.Errorf("%d: unexpected target: %v, expected %v", i, target, c.target) | ||
} | ||
if c.ok != ok { | ||
t.Errorf("%d: unexpected ok: %v, expected %v", i, ok, c.ok) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -602,12 +602,15 @@ func TestConvertToVersion(t *testing.T) { | |
gv: unversioned.GroupVersion{Version: "__internal"}, | ||
out: &TestType1{A: "test"}, | ||
}, | ||
// prefers the first group version in the list | ||
// prefers the best match | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't remove the test, change the output and then add a second test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2nd test is not needed since the previous one is touching the conversion from external to internal if such GV is passed. I'll fix the output for this test, only. |
||
{ | ||
scheme: GetTestScheme(), | ||
in: &ExternalTestType1{A: "test"}, | ||
gv: unversioned.GroupVersions{{Version: "__internal"}, {Version: "v1"}}, | ||
out: &TestType1{A: "test"}, | ||
out: &ExternalTestType1{ | ||
MyWeirdCustomEmbeddedVersionKindField: MyWeirdCustomEmbeddedVersionKindField{APIVersion: "v1", ObjectKind: "TestType1"}, | ||
A: "test", | ||
}, | ||
}, | ||
// unversioned type returned as-is | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem logically equivalent to what we had before - if no exact match exists, you need to pick the first target.