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

Testing FSM objects: reflect.DeepEqual fails when FSM attribute is set on an object #73

Open
nvjkmr opened this issue Aug 15, 2021 · 1 comment
Labels

Comments

@nvjkmr
Copy link

nvjkmr commented Aug 15, 2021

We use testify mocks for mocking objects while testing (uses reflect.DeepEqual to compare).

We are using FSM on a model (has FSM property) and when this object is passed around to repo layer for saving, we mock the Save method in our tests. The problem is that, the tests fail because ob.FSM property doesn't match with the expected object's property.

To work around this we have to strip the FSM property (set ob.FSM = nil) and pass it to Save so that the object matching is successful. Is there a correct way to handle this?

@maxekman
Copy link
Member

maxekman commented Nov 1, 2021

I would look into the cmp.Equals() function instead, possibly with a helper to compare FSMs.

https://pkg.go.dev/github.com/google/go-cmp/cmp

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

No branches or pull requests

2 participants