Add json-patch v4 compatibility test

Kubernetes-commit: d180fe28ad5154eae7930a518640a8860e5a96d8
This commit is contained in:
Jordan Liggitt 2025-06-24 09:23:39 -04:00 committed by Kubernetes Publisher
parent 75e69719a1
commit 3d4aed0ded
1 changed files with 10 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/google/go-cmp/cmp"
jsonpatch "gopkg.in/evanphx/json-patch.v4"
apiequality "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -249,6 +250,15 @@ func TestJSONPatch(t *testing.T) {
name: "valid-negative-index-patch",
patch: `[{"op": "test", "value": "foo", "path": "/metadata/finalizers/-1"}]`,
},
// This demonstrates out-of-spec behavior json-patch v4 allows,
// which Kubernetes clients may depend on, and which updating to json-patch v5 currently breaks
{
name: "replace-missing-path-allowed",
patch: `[
{"op":"replace", "path":"/metadata/path", "value":"foo"},
{"op":"test", "path":"/metadata/path", "value":"foo"}
]`,
},
} {
p := &patcher{
patchType: types.JSONPatchType,