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

Function TestChannelHistoryLegacyDoc

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

Source from the content-addressed store, hash-verified

2667}
2668
2669func TestChannelHistoryLegacyDoc(t *testing.T) {
2670 defer db.SuspendSequenceBatching()()
2671
2672 rt := NewRestTester(t, &RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction})
2673 defer rt.Close()
2674
2675 docData := `
2676 {
2677 "channels": [
2678 "test"
2679 ],
2680 "_sync": {
2681 "rev": "1-08267a64bf0e3963bab7dece1ea0887a",
2682 "sequence": 1,
2683 "recent_sequences": [
2684 1
2685 ],
2686 "history": {
2687 "revs": [
2688 "1-08267a64bf0e3963bab7dece1ea0887a"
2689 ],
2690 "parents": [
2691 -1
2692 ],
2693 "channels": [
2694 [
2695 "test"
2696 ]
2697 ]
2698 },
2699 "channels": {
2700 "test": null
2701 },
2702 "cas": "",
2703 "value_crc32c": "",
2704 "time_saved": "2021-05-04T18:37:07.559778+01:00"
2705 }
2706 }`
2707
2708 // Insert raw 'legacy' doc with no channel history info
2709 err := rt.GetSingleDataStore().Set("doc1", 0, nil, []byte(docData))
2710 assert.NoError(t, err)
2711
2712 var body db.Body
2713
2714 // Get doc and ensure its available
2715 resp := rt.SendAdminRequest("GET", "/{{.keyspace}}/doc1", "")
2716 RequireStatus(t, resp, http.StatusOK)
2717
2718 // Remove doc from channel and ensure that channel history is built correctly with current end sequence and
2719 // setting start sequence
2720 resp = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc1?rev=1-08267a64bf0e3963bab7dece1ea0887a", `{"channels": []}`)
2721 RequireStatus(t, resp, http.StatusCreated)
2722 err = json.Unmarshal(resp.BodyBytes(), &body)
2723 assert.NoError(t, err)
2724 collection, ctx := rt.GetSingleTestDatabaseCollection()
2725 syncData, err := collection.GetDocSyncData(ctx, "doc1")
2726 assert.NoError(t, err)

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
GetSingleDataStoreMethod · 0.95
SendAdminRequestMethod · 0.95
SuspendSequenceBatchingFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
GetDocSyncDataMethod · 0.80
LenMethod · 0.65
ContainsMethod · 0.65
SetMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected