Skip to content

Patching a nil *int? #107

@stoffen

Description

@stoffen

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())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions