Skip to content

Commit

Permalink
Merge pull request #236 from go-kivik/bulk-v3
Browse files Browse the repository at this point in the history
Fix BulkGet function
  • Loading branch information
flimzy authored Apr 28, 2020
2 parents 9bcfa60 + 8e81de1 commit 4de1563
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bulkget.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ func (d *db) BulkGet(ctx context.Context, docs []driver.BulkGetReference, opts m
if err != nil {
return nil, err
}
body := map[string]interface{}{
"docs": docs,
}
options := &chttp.Options{
Query: query,
GetBody: chttp.BodyEncoder(docs),
GetBody: chttp.BodyEncoder(body),
Header: http.Header{
chttp.HeaderIdempotencyKey: []string{},
},
Expand Down
21 changes: 21 additions & 0 deletions bulkget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -134,6 +135,26 @@ func TestBulkGet(t *testing.T) {
Doc: []byte(`{"_id":"test1","_rev":"4-8158177eb5931358b3ddaadd6377cf00","moo":123,"oink":true,"_revisions":{"start":4,"ids":["8158177eb5931358b3ddaadd6377cf00","1c08032eef899e52f35cbd1cd5f93826","e22bea278e8c9e00f3197cb2edee8bf4","7d6ff0b102072755321aa0abb630865a"]},"_attachments":{"foo.txt":{"content_type":"text/plain","revpos":2,"digest":"md5-WiGw80mG3uQuqTKfUnIZsg==","length":9,"stub":true}}}`),
},
})
tests.Add("request", func(t *testing.T) interface{} {
return tst{
db: &db{
client: newCustomClient(func(r *http.Request) (*http.Response, error) {
defer r.Body.Close() // nolint:errcheck
if d := testy.DiffAsJSON(testy.Snapshot(t), r.Body); d != nil {
return nil, fmt.Errorf("Unexpected request: %s", d)
}
return nil, errors.New("success")
}),
dbName: "xxx",
},
docs: []driver.BulkGetReference{
{ID: "foo"},
{ID: "bar"},
},
status: 502,
err: "success",
}
})

tests.Run(t, func(t *testing.T, test tst) {
rows, err := test.db.BulkGet(context.Background(), test.docs, test.options)
Expand Down
2 changes: 1 addition & 1 deletion chttp/chttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
// The default UserAgent values
const (
UserAgent = "Kivik chttp"
Version = "3.0.2"
Version = "3.0.4"
)

// Client represents a client connection. It embeds an *http.Client
Expand Down
2 changes: 1 addition & 1 deletion constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package couchdb

// Version is the current version of this package.
const Version = "3.0.2"
const Version = "3.0.4"

const (
// OptionFullCommit is the option key used to set the `X-Couch-Full-Commit`
Expand Down
10 changes: 10 additions & 0 deletions testdata/TestBulkGet_request
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"docs": [
{
"id": "foo"
},
{
"id": "bar"
}
]
}

0 comments on commit 4de1563

Please sign in to comment.