diff icon indicating copy to clipboard operation
diff copied to clipboard

Patching a nil *int?

Open stoffen opened this issue 1 year ago • 0 comments

Howdy!

What am I missing here: I am unable to patch my "blank" struct property. The last assertion fails with reflect: call of reflect.Value.Type on zero Value.

type PatchStruct struct {
	Variable *int `json:"Variable"`
}

func TestPatch(t *testing.T) {
	changes := []diff.Change{
		{
			Type: "update",
			Path: []string{"Variable"},
			From: nil,
			To:   4,
		},
	}

	var patchMe PatchStruct
	d, err := diff.NewDiffer(diff.ConvertCompatibleTypes())
	assert.NoError(t, err)

	result := d.Patch(changes, &patchMe)
	assert.False(t, result.HasErrors())
}

stoffen avatar Nov 10 '23 20:11 stoffen