I am using the official Mongo driver for Go. My code looks like this (omitted error handling in order to make the example simpler):
type DB struct {
collection *mongo.Collection
}
func (db DB) GetUsers() []*User {
res, _ := db.collection.Find(context.TODO(), bson.M{})
var users []*User
res.All(context.TODO(), &users)
return users
}
Question: How to unit test the GetUsers
function?
I went through the driver's documentation and didn't find any testing related functionality/best practices.
Note: The full code is available on GitHub.