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

Export SingleResult fields

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Community Answered
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Testing
    • Labels:
      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

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: