mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 00:07:50 +00:00
Negative index regression test for json-patch (#122625)
* add testcase with negative index * exercise successful negative index patching * use different values for testing Co-authored-by: Chris Bandy <bandy.chris@gmail.com> --------- Co-authored-by: Chris Bandy <bandy.chris@gmail.com>
This commit is contained in:
parent
a02a00ecd7
commit
83ff8a2f49
@ -244,6 +244,10 @@ func TestJSONPatch(t *testing.T) {
|
||||
expectedError: "the server rejected our request due to an error in our request",
|
||||
expectedErrorType: metav1.StatusReasonInvalid,
|
||||
},
|
||||
{
|
||||
name: "valid-negative-index-patch",
|
||||
patch: `[{"op": "test", "value": "foo", "path": "/metadata/finalizers/-1"}]`,
|
||||
},
|
||||
} {
|
||||
p := &patcher{
|
||||
patchType: types.JSONPatchType,
|
||||
@ -253,6 +257,7 @@ func TestJSONPatch(t *testing.T) {
|
||||
codec := codecs.LegacyCodec(examplev1.SchemeGroupVersion)
|
||||
pod := &examplev1.Pod{}
|
||||
pod.Name = "podA"
|
||||
pod.ObjectMeta.Finalizers = []string{"foo"}
|
||||
versionedJS, err := runtime.Encode(codec, pod)
|
||||
if err != nil {
|
||||
t.Errorf("%s: unexpected error: %v", test.name, err)
|
||||
|
@ -289,6 +289,26 @@ func TestJSONPatch(t *testing.T) {
|
||||
fragment: `[ {"op": "add", "path": "/metadata/labels/foo", "value": "bar"} ]`,
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
obj: &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Finalizers: []string{"foo", "bar", "test"},
|
||||
},
|
||||
},
|
||||
fragment: `[ {"op": "replace", "path": "/metadata/finalizers/-1", "value": "baz"} ]`,
|
||||
expected: &corev1.Pod{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Pod",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
Finalizers: []string{"foo", "bar", "baz"},
|
||||
},
|
||||
Spec: corev1.PodSpec{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
codec := runtime.NewCodec(scheme.DefaultJSONEncoder(),
|
||||
|
Loading…
Reference in New Issue
Block a user