Skip to content

Commit 3d5f11b

Browse files
committed
Add testcases covering large valid patches
1 parent 1da2d00 commit 3d5f11b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/integration/apiserver/max_request_body_bytes_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ func TestMaxResourceSize(t *testing.T) {
9393
t.Errorf("expected success or bad request err, got %v", err)
9494
}
9595
})
96+
t.Run("JSONPatchType should handle a valid patch just under the max limit", func(t *testing.T) {
97+
patchBody := []byte(`[{"op":"add","path":"/foo","value":0` + strings.Repeat(" ", 3*1024*1024-100) + `}]`)
98+
err = rest.Patch(types.JSONPatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
99+
Body(patchBody).Do().Error()
100+
if err != nil {
101+
t.Errorf("unexpected error: %v", err)
102+
}
103+
})
96104
t.Run("MergePatchType should handle a patch just under the max limit", func(t *testing.T) {
97105
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
98106
err = rest.Patch(types.MergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
@@ -101,6 +109,14 @@ func TestMaxResourceSize(t *testing.T) {
101109
t.Errorf("expected success or bad request err, got %v", err)
102110
}
103111
})
112+
t.Run("MergePatchType should handle a valid patch just under the max limit", func(t *testing.T) {
113+
patchBody := []byte(`{"value":0` + strings.Repeat(" ", 3*1024*1024-100) + `}`)
114+
err = rest.Patch(types.MergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
115+
Body(patchBody).Do().Error()
116+
if err != nil {
117+
t.Errorf("unexpected error: %v", err)
118+
}
119+
})
104120
t.Run("StrategicMergePatchType should handle a patch just under the max limit", func(t *testing.T) {
105121
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
106122
err = rest.Patch(types.StrategicMergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
@@ -109,6 +125,14 @@ func TestMaxResourceSize(t *testing.T) {
109125
t.Errorf("expected success or bad request err, got %v", err)
110126
}
111127
})
128+
t.Run("StrategicMergePatchType should handle a valid patch just under the max limit", func(t *testing.T) {
129+
patchBody := []byte(`{"value":0` + strings.Repeat(" ", 3*1024*1024-100) + `}`)
130+
err = rest.Patch(types.StrategicMergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
131+
Body(patchBody).Do().Error()
132+
if err != nil {
133+
t.Errorf("unexpected error: %v", err)
134+
}
135+
})
112136
t.Run("ApplyPatchType should handle a patch just under the max limit", func(t *testing.T) {
113137
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
114138
err = rest.Patch(types.ApplyPatchType).Param("fieldManager", "test").AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
@@ -117,6 +141,14 @@ func TestMaxResourceSize(t *testing.T) {
117141
t.Errorf("expected success or bad request err, got %#v", err)
118142
}
119143
})
144+
t.Run("ApplyPatchType should handle a valid patch just under the max limit", func(t *testing.T) {
145+
patchBody := []byte(`{"apiVersion":"v1","kind":"Secret"` + strings.Repeat(" ", 3*1024*1024-100) + `}`)
146+
err = rest.Patch(types.ApplyPatchType).Param("fieldManager", "test").AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
147+
Body(patchBody).Do().Error()
148+
if err != nil {
149+
t.Errorf("unexpected error: %v", err)
150+
}
151+
})
120152
t.Run("Delete should limit the request body size", func(t *testing.T) {
121153
err = c.Delete().AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
122154
Body(hugeData).Do().Error()

0 commit comments

Comments
 (0)