diff --git a/bulkget.go b/bulkget.go index 7c677d7d..5c9fb8c4 100644 --- a/bulkget.go +++ b/bulkget.go @@ -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{}, }, diff --git a/bulkget_test.go b/bulkget_test.go index 00e11b34..c09284a0 100644 --- a/bulkget_test.go +++ b/bulkget_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "io/ioutil" "net/http" @@ -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) diff --git a/chttp/chttp.go b/chttp/chttp.go index c5795ee6..04e9da74 100644 --- a/chttp/chttp.go +++ b/chttp/chttp.go @@ -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 diff --git a/constants.go b/constants.go index f574e913..776faf62 100644 --- a/constants.go +++ b/constants.go @@ -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` diff --git a/testdata/TestBulkGet_request b/testdata/TestBulkGet_request new file mode 100644 index 00000000..cc4255bc --- /dev/null +++ b/testdata/TestBulkGet_request @@ -0,0 +1,10 @@ +{ + "docs": [ + { + "id": "foo" + }, + { + "id": "bar" + } + ] +} \ No newline at end of file