-
Type: New Feature
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Testing
-
None
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.
- is related to
-
GODRIVER-1241 Mocking library
- Development Complete