[GODRIVER-2805] mtest: Add a way to check if all MockResponses have been consumed Created: 12/Apr/23  Updated: 27/Oct/23  Resolved: 06/Jul/23

Status: Closed
Project: Go Driver
Component/s: Testing
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Trivial - P5
Reporter: Stavros Tsompanidis Assignee: Qingyang Hu
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Scenario:

You create a unit test with 5 mock responses, and you want to make sure that each of those responses will be consumed.

Example:

We have collection A and B. We want to asure in unit test, that when there is an insert on collection A, an insert on collection B will be executed. So we need a method NoRemainingMockResponses() which returns true if all mock responses had consumed.



 Comments   
Comment by PM Bot [ 06/Jul/23 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to reopen this ticket if you're still experiencing the issue, and add a comment if you're able to provide more information.

Comment by PM Bot [ 28/Jun/23 ]

Hi stavtsob@gmail.com! GODRIVER-2805 is awaiting your response.

If this is still an issue for you, please open Jira to review the latest status and provide your feedback. Thanks!

Comment by Qingyang Hu [ 20/Jun/23 ]

Hello stavtsob@gmail.com,

We appreciate you bringing this issue to our attention. However, we suggest Go driver users not to use the mtest package in their projects. The mtest package mainly focuses on internal testing. Thus, it is subject to change. Instead, we plan to move mtest into an internal directory in GODRIVER-2724 for Go driver 2.0 to avoid confusion and misuse.

We apologize for the inconvenience. Please feel free to leave a comment if you have more concerns.

Comment by Stavros Tsompanidis [ 18/Apr/23 ]

I also wrote the code for this feature:

File: mongo/integration/mtest/mongotest.go

func (t *T) RemainingMockResponses() int {
    return len(t.mockDeployment.conn.responses)
}

Comment by Stavros Tsompanidis [ 18/Apr/23 ]

esha.bhargava@mongodb.com Example: We are testing a method which is updating the document of collection A. Also while updating the object A, we want to create a document in a different collection B, if some conditions are met. The creation of the document in collection B must not throw an error in case of failure.
So while we are writing the test for this method, we mock the responses for the collection A, and we make the conditions for the creation of the document for B to be met. But because the block that creates this document (B) does not throw an error in case of failure, how do we know that the code went into the if statement? Only if we knew that the we have mocked the insert response to the collection B and it has been consumed.

Comment by Esha Bhargava [ 17/Apr/23 ]

stavtsob@gmail.com  Thank you for reporting this issue. Can you elaborate on what kind of interactions with the database are you trying to mock? Can you provide an example test case where you use mock responses?

Generated at Thu Feb 08 08:39:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.