go-sqlmock icon indicating copy to clipboard operation
go-sqlmock copied to clipboard

When expectations are not met show received argument values

Open Stefos opened this issue 6 years ago • 2 comments
trafficstars

I am trying to test the execution of an UPDATE query. The output of the failed execution is:

there were unfulfilled expectations: there is a remaining expectation which was not matched: ExpectedExec => expecting Exec or ExecContext which:
		  - matches sql: 'UPDATE `issue`'
		  - is with arguments:
		    0 - 3
		    1 - Issue_1_updated
		    2 - Issue_1_updated
		    3 - 
		    4 - 
		    5 - 1
		    6 - true
		    7 - true
		    8 - <nil>
		    9 - {}
		    10 - <nil>
		    11 - 1
		  - should return Result having:
		      LastInsertId: 1
		      RowsAffected: 1
FAIL

I was able to understand what didn't match by playing with sqlmock.AnyArg(). Rather than having to do that it would be helpful to have an output that tells me what values where received as arguments as well, so I can quickly do a visual comparison of what was expected and what were the actual values used.

Stefos avatar Jan 31 '19 17:01 Stefos

@l3pp4rd Wonder what the chances of making this happen are, or if there's a workaround.

emptonaut avatar Sep 20 '19 16:09 emptonaut

Hi, I agree this could be helpful, but currently I’m too busy with a child. If you could contribute it, that would be useful

l3pp4rd avatar Sep 20 '19 16:09 l3pp4rd