Open Tang8330 opened 6 years ago
@Tang8330 I don't know about PutItemInput.Item
why its different.
You could mock with argumentMatcher, also assert the argument properly using mock.MatchedBy
. Add custom/partial match against the passed argument with an expected one, match only fields which are necessary.
dbMock.On("PutItem", mock.MatchedBy(itemMatcher(expectedItem)))
func itemMatcher(expected *dynamodb.PutItemInput) func(*dynamodb.PutItemInput) bool {
return func(actual *dynamodb.PutItemInput) {
return expected.Item["account#user"] == actual.Item["account#user"] &&
expected.TableName == actual.TableName // add other necessary fields
}
}
Hope this helps.
@devdinu Thanks for that, it certainly did help!
It would be great to get to the bottom of why the object was not picked up by the mocking library. Your suggestion has greatly improved my workaround solution and thank you for that.
I'm trying to mock
PutItem(*dynamodb.PutItemInput)
from AWS Dynamo Package GoDoc hereHowever, I'm running into a bunch of problems that look something like this:
I've tried a couple of things:
func (db mockDynamo) ExpectPutItem(putItemInput dynamodb.PutItemInput, putItemOutput *dynamodb.PutItemOutput, withErr error) { db.On("PutItem", putItemInput).Return(putItemOutput, withErr).Once() }