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

Function TestChangesFeedCVWithOldRevOnlyData

rest/changes_test.go:628–675  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

626}
627
628func TestChangesFeedCVWithOldRevOnlyData(t *testing.T) {
629 rt := NewRestTester(t, nil)
630 defer rt.Close()
631
632 seq, err := db.AllocateTestSequence(rt.GetDatabase())
633 require.NoError(t, err)
634 oldDoc := "oldDoc"
635 oldDocBody := `{"body_field":"1234"}`
636 oldDocSyncData := []byte(fmt.Sprintf(`{"sequence":%d,"rev":{"rev": "1-abc"},"history":{"revs":["1-abc"],"parents":[-1],"channels":[null]},"value_crc32c":"%s"}`, seq, base.Crc32cHashString([]byte(oldDocBody))))
637 _, err = rt.GetSingleDataStore().WriteWithXattrs(t.Context(), oldDoc, 0, 0, []byte(oldDocBody), map[string][]byte{base.SyncXattrName: oldDocSyncData}, nil, nil)
638 require.NoError(t, err)
639
640 newDoc := "newDoc"
641 newDocBody := `{"foo":"bar"}`
642 rt.PutDoc(newDoc, newDocBody)
643
644 rt.WaitForPendingChanges()
645
646 resp := rt.SendAdminRequest(http.MethodGet, "/{{.keyspace}}/_changes?version_type=cv&include_docs=true", "")
647 RequireStatus(t, resp, http.StatusOK)
648 var changesResults ChangesResults
649 require.NoError(t, base.JSONUnmarshal(resp.Body.Bytes(), &changesResults))
650 require.Len(t, changesResults.Results, 2)
651 for i, changeEntry := range changesResults.Results {
652 for _, change := range changeEntry.Changes {
653 require.Len(t, change, 1) // ensure only one version type is present
654 // and that it was the expected one (and we have a value)
655 var expectedType db.ChangesVersionType
656 if i == 0 {
657 // first doc was written with a RevID and no CV available
658 expectedType = db.ChangesVersionTypeRevTreeID
659 } else {
660 expectedType = db.ChangesVersionTypeCV
661 }
662 versionValue, ok := change[expectedType]
663 require.Truef(t, ok, "Expected version type %s, got %v", expectedType, change)
664 require.NotEmpty(t, versionValue)
665 }
666 var expectedBody string
667 switch changeEntry.ID {
668 case oldDoc:
669 expectedBody = oldDocBody
670 case newDoc:
671 expectedBody = newDocBody
672 }
673 require.Contains(t, string(changeEntry.Doc), expectedBody[1:len(expectedBody)-1]) // strip {}s from doc body - 1.x API stamps additional properties so accommodate
674 }
675}

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
GetDatabaseMethod · 0.95
GetSingleDataStoreMethod · 0.95
PutDocMethod · 0.95
WaitForPendingChangesMethod · 0.95
SendAdminRequestMethod · 0.95
AllocateTestSequenceFunction · 0.92
Crc32cHashStringFunction · 0.92
JSONUnmarshalFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
ContextMethod · 0.65

Tested by

no test coverage detected