fsm
fsm copied to clipboard
Testing FSM objects: reflect.DeepEqual fails when FSM attribute is set on an object
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?
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