Add tests for accept content-type fallback
This commit is contained in:
		| @@ -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,13 +2114,23 @@ 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 test.expected != nil { | ||||||
|  | 			itemOut, d, err := extractBodyObject(resp, metainternalversion.Codecs.LegacyCodec(metav1alpha1.SchemeGroupVersion)) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				t.Fatal(err) | 				t.Fatal(err) | ||||||
| 			} | 			} | ||||||
| 			if !reflect.DeepEqual(test.expected, itemOut) { | 			if !reflect.DeepEqual(test.expected, itemOut) { | ||||||
| 				t.Errorf("%d: did not match: %s", i, diff.ObjectReflectDiff(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 { | ||||||
| 			t.Fatal(err) | 			t.Fatal(err) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jordan Liggitt
					Jordan Liggitt