Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patching a nil *int? #107

Open
stoffen opened this issue Nov 10, 2023 · 0 comments
Open

Patching a nil *int? #107

stoffen opened this issue Nov 10, 2023 · 0 comments

Comments

@stoffen
Copy link

stoffen commented Nov 10, 2023

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())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant