The tests would fail with the message but it did return the expected error from the batch!
Returned error: "Some Error" // Correct error returned from the batch!
db_test.go:154: there were unfulfilled expectations: there is a remaining expectation which was not matched: ExpectedQuery => expecting call to Query() or to QueryRow():
- matches sql: 'SELECT'
- is without arguments
- returns data:
row 0 - [2]
So we thought, this can be an expected error since the first query returns an error, the second is not executed (even though a batch should execute all of them I believe). When we removed the second ExpectQuery we got a different error:
Returned error: "call to method Batch() was not expected"
db_test.go:154: there were unfulfilled expectations: there is a remaining expectation which was not matched: ExpectedBatch => expecting call to SendBatch()
This error is expected I believe as the batch has two select statements, to the "expector" is not expecting a Batch() as the second query was not expected.
The final attempt we did was to return the error on the second query instead:
Expected behavior
I would expect the batch to return the expected error but not complain about missing expectations. I would expect testcase TestNewBatchErrorFail1 to succeed. But this might be a limitation of batch queries with PGX as well, I am not sure about this :slightly_smiling_face:
Describe the bug We are implementing batch queries as in some cases we execute a batch of queries that can benefit from a single round trip.
When writing tests we wanted to mock errors as well when we noticed that when we do:
The tests would fail with the message but it did return the expected error from the batch!
So we thought, this can be an expected error since the first query returns an error, the second is not executed (even though a batch should execute all of them I believe). When we removed the second
ExpectQuery
we got a different error:This error is expected I believe as the batch has two select statements, to the "expector" is not expecting a
Batch()
as the second query was not expected.The final attempt we did was to return the error on the second query instead:
This made the testcase pass without expectation errors.
To Reproduce A bit of pseudo code to simplify a testcase
Implementation on the database layer:
Testcases:
Expected behavior I would expect the batch to return the expected error but not complain about missing expectations. I would expect testcase
TestNewBatchErrorFail1
to succeed. But this might be a limitation of batch queries with PGX as well, I am not sure about this :slightly_smiling_face: