moov-io / iso8583

A golang implementation to marshal and unmarshal iso8583 message.
https://moov.io
Apache License 2.0
350 stars 104 forks source link

Message and Field Equality Functions #116

Open krishishah opened 3 years ago

krishishah commented 3 years ago

For testing purposes it'd be really valuable to have message and field equality functions.

Currently, in order to check whether two messages are equal, we are forced to manually assert on every field (including nil ones) to ensure that every value is equal.

It would be great to have equality functions for messages that recursively check that fields and subfields are either nil or have equal values.

The same should be possible on a field / subfield level as well. This likely requires us to extend the field.Field interface to have an Equal(Field) bool function as well.

For the Message object, we could either add on a Equal(m *Message) bool method onto the *Message receiver or add on a utility function along the lines of: func Equal(x *Message, y *Message) bool

krishishah commented 3 years ago

Looks like implementing T Equal(T) bool would make objects compatible with: https://pkg.go.dev/github.com/google/go-cmp/cmp#Equal