我正在尝试使用该mtest包(https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo/integration/mtest)对我的 MongoDB 调用执行一些模拟结果测试,但我可以似乎不知道如何正确模拟调用集合*mongo.UpdateResult时返回的值。UpdateOne(...)
这是演示该问题的片段:
package test
import (
    "context"
    "errors"
    "testing"
    "github.com/stretchr/testify/assert"
    "go.mongodb.org/mongo-driver/bson"
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/integration/mtest"
)
func UpdateOneCall(mongoClient *mongo.Client) error {
    filter := bson.D{{Key: "SomeIDField", Value: "SomeID"}}
    update := bson.D{{Key: "$set", Value: bson.D{{Key: "ANewField", Value: true}}}}
    collection := mongoClient.Database("SomeDatabase").Collection("SomeCollection")
    updateResult, err := collection.UpdateOne(context.Background(), filter, update)
    if err != nil {
        return err
    }
    if updateResult.ModifiedCount != 1 {
        return errors.New("no field was updated")
    }
    return nil
}
func TestUpdateOneCall(t *testing.T) {
    mt := …