diff --git a/testing/fixture.go b/testing/fixture.go index d288a3aa..15b3e533 100644 --- a/testing/fixture.go +++ b/testing/fixture.go @@ -214,6 +214,7 @@ func (o objectTrackerReact) Apply(action PatchActionImpl) (runtime.Object, error if err := yaml.Unmarshal(action.GetPatch(), &patchObj.Object); err != nil { return nil, err } + patchObj.SetName(action.GetName()) err := o.tracker.Apply(gvr, patchObj, ns, action.PatchOptions) if err != nil { return nil, err diff --git a/testing/fixture_test.go b/testing/fixture_test.go index e2a5ea8f..f950bd69 100644 --- a/testing/fixture_test.go +++ b/testing/fixture_test.go @@ -294,12 +294,33 @@ func TestApplyCreate(t *testing.T) { handled, configMap, err := reaction(action) assert.True(t, handled) if err != nil { - t.Errorf("Failed to create a resource with apply: %v", err) + t.Fatalf("Failed to create a resource with apply: %v", err) } cm := configMap.(*v1.ConfigMap) assert.Equal(t, cm.Data, map[string]string{"k": "v"}) } +func TestApplyNoMeta(t *testing.T) { + cmResource := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configMaps"} + scheme := runtime.NewScheme() + scheme.AddKnownTypes(cmResource.GroupVersion(), &v1.ConfigMap{}) + codecs := serializer.NewCodecFactory(scheme) + o := NewFieldManagedObjectTracker(scheme, codecs.UniversalDecoder(), configMapTypeConverter(scheme)) + + reaction := ObjectReaction(o) + patch := []byte(`{"apiVersion": "v1", "kind": "ConfigMap", "data": {"k": "v"}}`) + action := NewPatchActionWithOptions(cmResource, "default", "cm-1", types.ApplyPatchType, patch, + metav1.PatchOptions{FieldManager: "test-manager"}) + handled, configMap, err := reaction(action) + assert.True(t, handled) + if err != nil { + t.Fatalf("Failed to create a resource with apply: %v", err) + } + cm := configMap.(*v1.ConfigMap) + assert.Equal(t, "cm-1", cm.Name) + assert.Equal(t, map[string]string{"k": "v"}, cm.Data) +} + func TestApplyUpdateMultipleFieldManagers(t *testing.T) { cmResource := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configMaps"} scheme := runtime.NewScheme()