Add tests for accept content-type fallback

pull/6/head
Jordan Liggitt 2017-12-12 01:52:30 -05:00
parent ee13444144
commit 39721a2811
No known key found for this signature in database
GPG Key ID: 39928704103C7229
1 changed files with 34 additions and 6 deletions

View File

@ -2026,11 +2026,29 @@ func TestGetPartialObjectMetadata(t *testing.T) {
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1;g=meta.k8s.io",
statusCode: http.StatusNotAcceptable,
},
{
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1;g=meta.k8s.io, application/json",
expectKind: schema.GroupVersionKind{Kind: "Simple", Group: testGroupVersion.Group, Version: testGroupVersion.Version},
},
{
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1alpha1;g=meta.k8s.io, application/json",
expectKind: schema.GroupVersionKind{Kind: "PartialObjectMetadata", Group: "meta.k8s.io", Version: "v1alpha1"},
},
{
list: true,
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1alpha1;g=meta.k8s.io",
statusCode: http.StatusNotAcceptable,
},
{
list: true,
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1;g=meta.k8s.io, application/json",
expectKind: schema.GroupVersionKind{Kind: "SimpleList", Group: testGroupVersion.Group, Version: testGroupVersion.Version},
},
{
list: true,
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadataList;v=v1alpha1;g=meta.k8s.io, application/json",
expectKind: schema.GroupVersionKind{Kind: "PartialObjectMetadataList", Group: "meta.k8s.io", Version: "v1alpha1"},
},
{
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadataList;v=v1alpha1;g=meta.k8s.io",
statusCode: http.StatusNotAcceptable,
@ -2096,12 +2114,22 @@ func TestGetPartialObjectMetadata(t *testing.T) {
t.Errorf("%d: invalid status: %#v\n%s", i, resp, bodyOrDie(resp))
continue
}
itemOut, body, err := extractBodyObject(resp, metainternalversion.Codecs.LegacyCodec(metav1alpha1.SchemeGroupVersion))
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expected, itemOut) {
t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, itemOut))
body := ""
if test.expected != nil {
itemOut, d, err := extractBodyObject(resp, metainternalversion.Codecs.LegacyCodec(metav1alpha1.SchemeGroupVersion))
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(test.expected, itemOut) {
t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, itemOut))
}
body = d
} else {
d, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
body = string(d)
}
obj := &unstructured.Unstructured{}
if err := json.Unmarshal([]byte(body), obj); err != nil {