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

Improve list/map support for ObjectsAreEqual #1058

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

harryzcy
Copy link

@harryzcy harryzcy commented Mar 1, 2021

Summary

Function ObjectsAreEqual now compares two objects of type array/slice/map by iterating over each element. When two objects contain the same value but have different types, the function will now return true.

Changes

  • The function ObjectsAreEqualValues in assertion.go is changed.
  • Two helper functions listsAreEqualValues and mapsAreEqualValues are added.
  • Tests are added accordingly.

Motivation

Currently, assert.EqualValues would fail when two objects are of type array/slice/map and contain values of different types.

// assert would fail
assert.EqualValues(t, []interface{}{1}, []interface{}{int64(1)})

But, assert.EqualValues should always compare objects by value. So the above code should idealy pass.

Related issues

Closes #1057

Function `ObjectsAreEqual` now compares two objects of type array/slice/map by iterating over each element. When two objects contain the same value but have different types, the function will now return `true`.
@dolmen dolmen added pkg-assert Change related to package testify/assert assert.EqualValues About equality labels Oct 31, 2023
@joselitofilho
Copy link

Hi @harryzcy,

Thanks for your fix. Do you have any idea when this fix will be released?

@harryzcy
Copy link
Author

harryzcy commented Mar 4, 2024

Hi @harryzcy,

Thanks for your fix. Do you have any idea when this fix will be released?

No, I don't know when maintainers will review them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert.EqualValues About equality bug must-rebase pkg-assert Change related to package testify/assert
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testify assert.EqualValues should equate nested []interface{} by values
3 participants