fsm icon indicating copy to clipboard operation
fsm copied to clipboard

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

Open nvjkmr opened this issue 3 years ago • 1 comments

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?

nvjkmr avatar Aug 15 '21 15:08 nvjkmr

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

maxekman avatar Nov 01 '21 10:11 maxekman