chore: Add in gomock Matches receiver func
#408
+30
−0
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
Decimalstruct.gomockdefines aMatcherinterface, of which it requires:Matches(other {}interface) boolString() stringString()is already implemented, so i've implemented theMatchesfunction.Previously to work around this in places, I've been calling
String()on the 2Decimalvalues and comparing that. This doesn't work for comparing parameters with nestedDecimalvalues 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 aDecimalwhich isabs 1 exp 2.To save from writing complex
Matchesfunctions on every single struct which includes aDecimalor 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
*DecimalorDecimal, so happy to be steered either way.