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

Support Custom Equality and Diff in Assert and Require #1616

Open
nathanjsweet opened this issue Jun 25, 2024 · 1 comment
Open

Support Custom Equality and Diff in Assert and Require #1616

nathanjsweet opened this issue Jun 25, 2024 · 1 comment

Comments

@nathanjsweet
Copy link

Description

Update assert to compare data structures that are isomorphically equal (such as a Tree, Trie, etc) to one another, but not equal by value or reference.

Proposed solution

Define an Equal and Diff interface that structures can implement that the require/assert package will check on equality assertion (e.g. require.Equal(t, expected, actual)) rather than using DeepEqual.

Use case

Currently, the Cilium codebase uses a require.Truef as a workaround, calling into a custom Equals method and a custom Diff method.

@brackendawson
Copy link
Collaborator

brackendawson commented Oct 8, 2024

We are definately not going to change Equal to compare values any differently to how it does today, mostly because it is a breaking change.

Partly also because changing the definition of "equal" has led to issues before, as with the EqualValues assertion's problems. I'm also concerned that types will unintentionally satisfy this interface, time.Time from the standard library has an Equal method and it does not mean that the instances are equal, only that they represent the same instant.

Is there a way of proposing this as a compatible change with a reasonable level of safetly?

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

No branches or pull requests

2 participants