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

Function TestChannelQueryRevocation

db/database_test.go:3036–3112  ·  view source on GitHub ↗

TestChannelQueryRevocation ensures that the correct rev (revTreeID and cv) is returned by the channel query.

(t *testing.T)

Source from the content-addressed store, hash-verified

3034
3035// TestChannelQueryRevocation ensures that the correct rev (revTreeID and cv) is returned by the channel query.
3036func TestChannelQueryRevocation(t *testing.T) {
3037
3038 db, ctx := setupTestDB(t)
3039 defer db.Close(ctx)
3040 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
3041 _, err := collection.UpdateSyncFun(ctx, `function(doc, oldDoc) {
3042 channel(doc.channels);
3043 }`)
3044 require.NoError(t, err)
3045
3046 // Create doc with three channels (ABC, DEF, GHI)
3047 docID := "removalTestDoc"
3048 body := Body{"key1": "value1", "key2": 1234, "channels": []string{"ABC", "DEF", "GHI"}}
3049 rev1ID, _, err := collection.Put(ctx, docID, body)
3050 require.NoError(t, err, "Couldn't create document")
3051
3052 // Update the doc with a simple PUT to remove channel ABC
3053 updatedChannelBody := Body{"_rev": rev1ID, "key1": "value1", "key2": 1234, "channels": []string{"DEF", "GHI"}}
3054 _, rev2, err := collection.Put(ctx, docID, updatedChannelBody)
3055 require.NoError(t, err, "Couldn't update document via Put")
3056
3057 // Update the doc with PutExistingCurrentVersion to remove channel DEF
3058 /* TODO: requires fix to HLV conflict detection
3059 updatedChannelBody = Body{"_rev": rev2ID, "key1": "value1", "key2": 2345, "channels": "GHI"}
3060 existingDoc, err := collection.GetDocument(ctx, docID, DocUnmarshalAll)
3061 require.NoError(t, err)
3062 cblVersion := Version{SourceID: "CBLSource", Value: existingDoc.HLV.Version + 10}
3063 hlvErr := existingDoc.HLV.AddVersion(cblVersion)
3064 require.NoError(t, hlvErr)
3065 existingDoc.UpdateBody(updatedChannelBody)
3066 rev3, _, _, err := collection.PutExistingCurrentVersion(ctx, existingDoc, *existingDoc.HLV, nil)
3067 require.NoError(t, err, "Couldn't update document via PutExistingCurrentVersion")
3068
3069 */
3070
3071 var entries LogEntries
3072
3073 // Test query retrieval via star channel and named channel (queries use different indexes)
3074 testCases := []struct {
3075 testName string
3076 channelName string
3077 expectedRev channels.RevAndVersion
3078 }{
3079 {
3080 testName: "removal by SGW write",
3081 channelName: "ABC",
3082 expectedRev: rev2.RevAndVersion,
3083 },
3084 /*
3085 {
3086 testName: "removal by CBL write",
3087 channelName: "DEF",
3088 expectedRev: rev3.RevAndVersion,
3089 },
3090 */
3091 }
3092
3093 for _, testCase := range testCases {

Callers

nothing calls this directly

Calls 10

HexCasToUint64Function · 0.92
setupTestDBFunction · 0.85
UpdateSyncFunMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.65
RunMethod · 0.65
LenMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected