MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestBulkDocs

Function TestBulkDocs

rest/api_test.go:405–532  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

403}
404
405func TestBulkDocs(t *testing.T) {
406 tests := []struct {
407 occKey string
408 }{
409 {occKey: db.BodyRev},
410 {occKey: db.BodyCV},
411 }
412
413 for _, test := range tests {
414 t.Run(test.occKey, func(t *testing.T) {
415 rt := NewRestTester(t, nil)
416 defer rt.Close()
417
418 const bulk1DocID = "bulk1"
419 const bulk2DocID = "bulk2"
420 const bulk3LocalDocID = "_local/bulk3"
421
422 // insert all
423
424 input := fmt.Sprintf(
425 `{"docs": [{%q:%q, %q:%d}, {%q:%q, %q:%d}, {%q:%q, %q:%d}]}`,
426 db.BodyId, bulk1DocID, "n", 1,
427 db.BodyId, bulk2DocID, "n", 2,
428 db.BodyId, bulk3LocalDocID, "n", 3,
429 )
430 response := rt.SendAdminRequest(http.MethodPost, "/{{.keyspace}}/_bulk_docs", input)
431 RequireStatus(t, response, http.StatusCreated)
432
433 // get persisted versions
434 bulk1Version, _ := rt.GetDoc(bulk1DocID)
435 bulk2Version, _ := rt.GetDoc(bulk2DocID)
436 bulk3Version, _ := rt.GetDoc(bulk3LocalDocID)
437
438 var docs []any
439 require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &docs))
440 assert.Equal(t, []any{
441 map[string]any{"rev": bulk1Version.RevTreeID, "cv": bulk1Version.CV.String(), "id": bulk1DocID},
442 map[string]any{"rev": bulk2Version.RevTreeID, "cv": bulk2Version.CV.String(), "id": bulk2DocID},
443 map[string]any{"rev": bulk3Version.RevTreeID, "id": bulk3LocalDocID},
444 }, docs)
445
446 // check stored docs
447 response = rt.SendAdminRequest(http.MethodGet, fmt.Sprintf("/{{.keyspace}}/%s", bulk1DocID), "")
448 RequireStatus(t, response, http.StatusOK)
449 assert.JSONEq(t, fmt.Sprintf(`{%q:%q, %q:%q, %q:%q, %q:%d}`,
450 db.BodyId, bulk1DocID,
451 db.BodyRev, bulk1Version.RevTreeID,
452 db.BodyCV, bulk1Version.CV,
453 "n", 1,
454 ), response.BodyString())
455 response = rt.SendAdminRequest(http.MethodGet, fmt.Sprintf("/{{.keyspace}}/%s", bulk2DocID), "")
456 RequireStatus(t, response, http.StatusOK)
457 assert.JSONEq(t, fmt.Sprintf(`{%q:%q, %q:%q, %q:%q, %q:%d}`,
458 db.BodyId, bulk2DocID,
459 db.BodyRev, bulk2Version.RevTreeID,
460 db.BodyCV, bulk2Version.CV,
461 "n", 2,
462 ), response.BodyString())

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
SendAdminRequestMethod · 0.95
GetDocMethod · 0.95
JSONUnmarshalFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
BodyStringMethod · 0.80
RunMethod · 0.65
StringMethod · 0.65
EqualMethod · 0.45
FatalfMethod · 0.45

Tested by

no test coverage detected