From 017b9a43e87973e8c8db4a9a37f02c949229ecaf Mon Sep 17 00:00:00 2001 From: Sean Blong Date: Fri, 9 Feb 2024 13:29:59 -0800 Subject: [PATCH] Adding unit test to ensure patches are skipped for missing paths. Signed-off-by: Sean Blong --- .../resource_modifiers_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/resourcemodifiers/resource_modifiers_test.go b/internal/resourcemodifiers/resource_modifiers_test.go index 648d827be..c6563c2e6 100644 --- a/internal/resourcemodifiers/resource_modifiers_test.go +++ b/internal/resourcemodifiers/resource_modifiers_test.go @@ -1650,6 +1650,35 @@ func TestResourceModifiers_conditional_patches(t *testing.T) { wantErr: false, wantObj: cmWithLabelAToB.DeepCopy(), }, + { + name: "missing condition path and skip patches", + rm: &ResourceModifiers{ + Version: "v1", + ResourceModifierRules: []ResourceModifierRule{ + { + Conditions: Conditions{ + GroupResource: "*", + Namespaces: []string{"fake"}, + Matches: []MatchRule{ + { + Path: "/metadata/labels/a/b", + Value: "c", + }, + }, + }, + MergePatches: []JSONMergePatch{ + { + PatchData: `{"metadata":{"labels":{"a":"c"}}}`, + }, + }, + }, + }, + }, + obj: cmWithLabelAToB.DeepCopy(), + groupResource: "configmaps", + wantErr: false, + wantObj: cmWithLabelAToB.DeepCopy(), + }, } for _, tt := range tests {