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

Function TestDocumentChannelHistory

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

Source from the content-addressed store, hash-verified

2616}
2617
2618func TestDocumentChannelHistory(t *testing.T) {
2619 defer db.SuspendSequenceBatching()()
2620
2621 rt := NewRestTester(t, &RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction})
2622 defer rt.Close()
2623
2624 var body db.Body
2625
2626 // Create doc in channel test and ensure a single channel history entry with only a start sequence
2627 // and no old channel history entries
2628 resp := rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc", `{"channels": ["test"]}`)
2629 RequireStatus(t, resp, http.StatusCreated)
2630 err := json.Unmarshal(resp.BodyBytes(), &body)
2631 assert.NoError(t, err)
2632 collection, ctx := rt.GetSingleTestDatabaseCollection()
2633 syncData, err := collection.GetDocSyncData(ctx, "doc")
2634 assert.NoError(t, err)
2635
2636 require.Len(t, syncData.ChannelSet, 1)
2637 assert.Equal(t, syncData.ChannelSet[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 0})
2638 assert.Len(t, syncData.ChannelSetHistory, 0)
2639
2640 // Update doc to remove from channel and ensure a single channel history entry with both start and end sequences
2641 // and no old channel history entries
2642 resp = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc?rev="+body["rev"].(string), `{"channels": []}`)
2643 RequireStatus(t, resp, http.StatusCreated)
2644 err = json.Unmarshal(resp.BodyBytes(), &body)
2645 assert.NoError(t, err)
2646 syncData, err = collection.GetDocSyncData(ctx, "doc")
2647 assert.NoError(t, err)
2648
2649 require.Len(t, syncData.ChannelSet, 1)
2650 assert.Equal(t, syncData.ChannelSet[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2})
2651 assert.Len(t, syncData.ChannelSetHistory, 0)
2652
2653 // Update doc to add to channels test and test2 and ensure a single channel history entry for both test and test2
2654 // both with start sequences only and ensure old test entry was moved to old
2655 resp = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc?rev="+body["rev"].(string), `{"channels": ["test", "test2"]}`)
2656 RequireStatus(t, resp, http.StatusCreated)
2657 err = json.Unmarshal(resp.BodyBytes(), &body)
2658 assert.NoError(t, err)
2659 syncData, err = collection.GetDocSyncData(ctx, "doc")
2660 assert.NoError(t, err)
2661
2662 require.Len(t, syncData.ChannelSet, 2)
2663 assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test", Start: 3, End: 0})
2664 assert.Contains(t, syncData.ChannelSet, db.ChannelSetEntry{Name: "test2", Start: 3, End: 0})
2665 require.Len(t, syncData.ChannelSetHistory, 1)
2666 assert.Equal(t, syncData.ChannelSetHistory[0], db.ChannelSetEntry{Name: "test", Start: 1, End: 2})
2667}
2668
2669func TestChannelHistoryLegacyDoc(t *testing.T) {
2670 defer db.SuspendSequenceBatching()()

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected