Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1186

Export SingleResult fields

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Testing
    • None

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            pedro.kiefer Pedro Kiefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: