Return 400 on invalid patch requests
This commit is contained in:
@@ -148,6 +148,70 @@ var cascDel = `
|
||||
}
|
||||
`
|
||||
|
||||
func Test4xxStatusCodeInvalidPatch(t *testing.T) {
|
||||
_, client, closeFn := setup(t)
|
||||
defer closeFn()
|
||||
|
||||
obj := []byte(`{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"name": "deployment",
|
||||
"labels": {"app": "nginx"}
|
||||
},
|
||||
"spec": {
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"app": "nginx"
|
||||
}
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"app": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest"
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}`)
|
||||
|
||||
resp, err := client.CoreV1().RESTClient().Post().
|
||||
AbsPath("/apis/apps/v1").
|
||||
Namespace("default").
|
||||
Resource("deployments").
|
||||
Body(obj).Do().Get()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create object: %v: %v", err, resp)
|
||||
}
|
||||
result := client.CoreV1().RESTClient().Patch(types.MergePatchType).
|
||||
AbsPath("/apis/apps/v1").
|
||||
Namespace("default").
|
||||
Resource("deployments").
|
||||
Name("deployment").
|
||||
Body([]byte(`{"metadata":{"annotations":{"foo":["bar"]}}}`)).Do()
|
||||
var statusCode int
|
||||
result.StatusCode(&statusCode)
|
||||
if statusCode != 422 {
|
||||
t.Fatalf("Expected status code to be 422, got %v (%#v)", statusCode, result)
|
||||
}
|
||||
result = client.CoreV1().RESTClient().Patch(types.StrategicMergePatchType).
|
||||
AbsPath("/apis/apps/v1").
|
||||
Namespace("default").
|
||||
Resource("deployments").
|
||||
Name("deployment").
|
||||
Body([]byte(`{"metadata":{"annotations":{"foo":["bar"]}}}`)).Do()
|
||||
result.StatusCode(&statusCode)
|
||||
if statusCode != 422 {
|
||||
t.Fatalf("Expected status code to be 422, got %v (%#v)", statusCode, result)
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that the apiserver returns 202 status code as expected.
|
||||
func Test202StatusCode(t *testing.T) {
|
||||
s, clientSet, closeFn := setup(t)
|
||||
|
Reference in New Issue
Block a user