mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 19:23:40 +00:00
Add tests for accept content-type fallback
This commit is contained in:
parent
ee13444144
commit
39721a2811
@ -2026,11 +2026,29 @@ func TestGetPartialObjectMetadata(t *testing.T) {
|
|||||||
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1;g=meta.k8s.io",
|
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1;g=meta.k8s.io",
|
||||||
statusCode: http.StatusNotAcceptable,
|
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,
|
list: true,
|
||||||
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1alpha1;g=meta.k8s.io",
|
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadata;v=v1alpha1;g=meta.k8s.io",
|
||||||
statusCode: http.StatusNotAcceptable,
|
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",
|
accept: runtime.ContentTypeJSON + ";as=PartialObjectMetadataList;v=v1alpha1;g=meta.k8s.io",
|
||||||
statusCode: http.StatusNotAcceptable,
|
statusCode: http.StatusNotAcceptable,
|
||||||
@ -2096,12 +2114,22 @@ func TestGetPartialObjectMetadata(t *testing.T) {
|
|||||||
t.Errorf("%d: invalid status: %#v\n%s", i, resp, bodyOrDie(resp))
|
t.Errorf("%d: invalid status: %#v\n%s", i, resp, bodyOrDie(resp))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
itemOut, body, err := extractBodyObject(resp, metainternalversion.Codecs.LegacyCodec(metav1alpha1.SchemeGroupVersion))
|
body := ""
|
||||||
if err != nil {
|
if test.expected != nil {
|
||||||
t.Fatal(err)
|
itemOut, d, err := extractBodyObject(resp, metainternalversion.Codecs.LegacyCodec(metav1alpha1.SchemeGroupVersion))
|
||||||
}
|
if err != nil {
|
||||||
if !reflect.DeepEqual(test.expected, itemOut) {
|
t.Fatal(err)
|
||||||
t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(test.expected, itemOut))
|
}
|
||||||
|
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{}
|
obj := &unstructured.Unstructured{}
|
||||||
if err := json.Unmarshal([]byte(body), obj); err != nil {
|
if err := json.Unmarshal([]byte(body), obj); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user