chore: Add in gomock Matches
receiver func
#408
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A pain point using this library is during testing, where equal numbers can be represented differently internally to the
Decimal
struct.gomock
defines aMatcher
interface, of which it requires:Matches(other {}interface) bool
String() string
String()
is already implemented, so i've implemented theMatches
function.Previously to work around this in places, I've been calling
String()
on the 2Decimal
values and comparing that. This doesn't work for comparing parameters with nestedDecimal
values usinggomock
.e.g.
myGomock.EXPECT().IncrementMyDecimal(ctx, decimal.NewFromInt(100)).Returns(decimal.NewFromInt(101))
This would fail to pass the expected parameter (100) as correct.
This is because case the internal representation expected is
abs 100 exp 0
, but during the execution of the code it gets aDecimal
which isabs 1 exp 2
.To save from writing complex
Matches
functions on every single struct which includes aDecimal
or from stringing them to compare, I've added this.If there's any feedback, it's welcome in terms of formatting, code cleanliness, linting etc.
I'm also not sure if it should be a receiver against
*Decimal
orDecimal
, so happy to be steered either way.