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

Function TestDeltaSyncWhenToRevIsChannelRemoval

db/database_test.go:1474–1573  ·  view source on GitHub ↗

Test delta sync behavior when the toRevision is a channel removal.

(t *testing.T)

Source from the content-addressed store, hash-verified

1472
1473// Test delta sync behavior when the toRevision is a channel removal.
1474func TestDeltaSyncWhenToRevIsChannelRemoval(t *testing.T) {
1475 t.Skip("Pending work for channel removal at rev cache CBG-3814")
1476 testCases := []struct {
1477 name string
1478 versionVector bool
1479 }{
1480 {
1481 name: "revTree test",
1482 versionVector: false,
1483 },
1484 {
1485 name: "versionVector test",
1486 versionVector: true,
1487 },
1488 }
1489 for _, testCase := range testCases {
1490 t.Run(testCase.name, func(t *testing.T) {
1491 db, ctx := setupTestDB(t)
1492 defer db.Close(ctx)
1493 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
1494 collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout)
1495
1496 // Create the first revision of doc1.
1497 rev1Body := Body{
1498 "k1": "v1",
1499 "channels": []string{"ABC", "NBC"},
1500 }
1501 rev1ID, _, err := collection.Put(ctx, "doc1", rev1Body)
1502 require.NoError(t, err, "Error creating doc")
1503
1504 // Create the second revision of doc1 on channel ABC as removal from channel NBC.
1505 rev2Body := Body{
1506 "k2": "v2",
1507 "channels": []string{"ABC"},
1508 BodyRev: rev1ID,
1509 }
1510 rev2ID, docRev2, err := collection.Put(ctx, "doc1", rev2Body)
1511 require.NoError(t, err, "Error creating doc")
1512
1513 // Create the third revision of doc1 on channel ABC.
1514 rev3Body := Body{
1515 "k3": "v3",
1516 "channels": []string{"ABC"},
1517 BodyRev: rev2ID,
1518 }
1519 rev3ID, docRev3, err := collection.Put(ctx, "doc1", rev3Body)
1520 require.NoError(t, err, "Error creating doc")
1521 require.NotEmpty(t, rev3ID, "Error creating doc")
1522
1523 // Flush the revision cache and purge the old revision backup.
1524 db.FlushRevisionCacheForTest()
1525 err = collection.PurgeOldRevisionJSON(ctx, "doc1", rev2ID)
1526 require.NoError(t, err, "Error purging old revision JSON")
1527
1528 // Request delta between rev1ID and rev2ID (toRevision "rev2ID" is channel removal)
1529 // as a user who doesn't have access to the removed revision via any other channel.
1530 authenticator := db.Authenticator(ctx)
1531 user, err := authenticator.NewUser("alice", "pass", base.SetOf("NBC"))

Callers

nothing calls this directly

Calls 15

NewChannelMapperFunction · 0.92
SetOfFunction · 0.92
HTTPErrorfFunction · 0.92
setupTestDBFunction · 0.85
PurgeOldRevisionJSONMethod · 0.80
NewUserMethod · 0.80
InitDeltaSyncStatsMethod · 0.80
GetDeltaMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected