[GODRIVER-1186] Export SingleResult fields Created: 03/Jul/19  Updated: 29/Oct/21  Resolved: 08/Jul/19

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

Type: New Feature Priority: Major - P3
Reporter: Pedro Kiefer Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to GODRIVER-1241 Mocking library Closed

 Description   

All fields on SingleResult are not exported, which makes really hard to mock a FindOne request.

For testing I've declared some interfaces, which let me use a mock instead of the driver.

```
type MongoCollection interface {
InsertOne(ctx context.Context, document interface{},
opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
FindOne(ctx context.Context, filter interface{},
opts ...*options.FindOneOptions) *mongo.SingleResult
DeleteOne(ctx context.Context, filter interface{},
opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
}
```

I can use mockgen to create a mock, but then I cannot create a fake `SingleResult`, only an empty one which only let me test an error situation.

Having the fields exported would let me test this easily.



 Comments   
Comment by Kristofer Brandow (Inactive) [ 08/Jul/19 ]

Hi pedro.kiefer,

We generally don't recommend mocking types that you don't own and suggest that users write database abstraction layers. We recommend using integration tests if you want to test the types from the mongo package.

--Kris

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