DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.06k stars 408 forks source link

When expectations are not met show received argument values #158

Open Stefos opened 5 years ago

Stefos commented 5 years ago

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.

emptonaut commented 4 years ago

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

l3pp4rd commented 4 years ago

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