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

Function TestChannelQuery

db/database_test.go:2956–3033  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2954}
2955
2956func TestChannelQuery(t *testing.T) {
2957
2958 db, ctx := setupTestDB(t)
2959 defer db.Close(ctx)
2960 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2961 _, err := collection.UpdateSyncFun(ctx, `function(doc, oldDoc) {
2962 channel(doc.channels);
2963 }`)
2964 require.NoError(t, err)
2965
2966 // Create doc
2967 body := Body{"key1": "value1", "key2": 1234, "channels": "ABC"}
2968 rev1ID, _, err := collection.Put(ctx, "doc1", body)
2969 require.NoError(t, err, "Couldn't create doc1")
2970
2971 // Create a doc to test removal handling. Needs three revisions so that the removal rev (2) isn't
2972 // the current revision
2973 removedDocID := "removed_doc"
2974 removedDocRev1, rev1, err := collection.Put(ctx, removedDocID, body)
2975 require.NoError(t, err, "Couldn't create removed_doc")
2976
2977 updatedChannelBody := Body{"_rev": removedDocRev1, "key1": "value1", "key2": 1234, "channels": "DEF"}
2978 removalRev, rev2, err := collection.Put(ctx, removedDocID, updatedChannelBody)
2979 require.NoError(t, err, "Couldn't update removed_doc")
2980
2981 updatedChannelBody = Body{"_rev": removalRev, "key1": "value1", "key2": 2345, "channels": "DEF"}
2982 _, rev3, err := collection.Put(ctx, removedDocID, updatedChannelBody)
2983 require.NoError(t, err, "Couldn't update removed_doc")
2984
2985 log.Printf("versions: [%v %v %v]", rev1.HLV.Version, rev2.HLV.Version, rev3.HLV.Version)
2986
2987 // TODO: check the case where the channel is removed with a putExistingRev mutation
2988
2989 var entries LogEntries
2990
2991 // Test query retrieval via star channel and named channel (queries use different indexes)
2992 testCases := []struct {
2993 testName string
2994 channelName string
2995 expectedRev channels.RevAndVersion
2996 }{
2997 {
2998 testName: "star channel",
2999 channelName: "*",
3000 expectedRev: rev3.RevAndVersion,
3001 },
3002 {
3003 testName: "named channel",
3004 channelName: "ABC",
3005 expectedRev: rev2.RevAndVersion,
3006 },
3007 }
3008
3009 for _, testCase := range testCases {
3010 t.Run(testCase.testName, func(t *testing.T) {
3011 entries, err = collection.getChangesInChannelFromQuery(ctx, testCase.channelName, 0, 100, 0, false)
3012 require.NoError(t, err)
3013

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected