Skip to content

Patching slice back to empty slice returns patchLog.Applied() to be false #91

Open
@jeffy-mathew

Description

@jeffy-mathew

patchLog.Applied() is false when we run the following code snippet regardless the patch operation works as expected.

package main

import (
	"fmt"

	"github.com/r3labs/diff/v3"
)

type Order struct {
	ID         string     `json:"id"`
	OrderItems OrderItems `json:"orderItems"`
}

type OrderItems struct {
	Items []string `json:"items"`
}

func main() {
	a := Order{
		ID: "1234",
	}

	b := Order{
		ID:         "1234",
		OrderItems: OrderItems{[]string{"1", "2", "4"}},
	}

	d, _ := diff.NewDiffer(diff.TagName("json"))

	changelog, _ := d.Diff(b, a)

	patchLog := d.Patch(changelog, &b)
	fmt.Printf("patchlog applied : %t \nhas errors %t \nerror count %d \n\n", patchLog.Applied(), patchLog.HasErrors(), patchLog.ErrorCount())

	fmt.Printf("values \n a: %#v \n b: %#v", a, b)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @jeffy-mathew

        Issue actions

          Patching slice back to empty slice returns patchLog.Applied() to be false · Issue #91 · r3labs/diff