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

Function TestRebuildUserChannelsNamedCollection

auth/auth_test.go:433–458  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

431}
432
433func TestRebuildUserChannelsNamedCollection(t *testing.T) {
434 ctx := base.TestCtx(t)
435 bucket := base.GetTestBucket(t)
436 defer bucket.Close(ctx)
437 dataStore := bucket.GetSingleDataStore()
438 computer := mockComputer{}
439 computer.AddChannelsForCollection("scope1", "collection1", ch.AtSequence(ch.BaseSetOf(t, "derived3", "derived4"), 1))
440
441 options := DefaultAuthenticatorOptions(ctx)
442 options.Collections = map[string]map[string]struct{}{
443 "scope1": {"collection1": struct{}{}},
444 }
445 auth := NewTestAuthenticator(t, dataStore, &computer, options)
446 user, err := auth.NewUser("testUser", "password", nil)
447 require.NoError(t, err)
448 user.SetCollectionExplicitChannels("scope1", "collection1", ch.AtSequence(ch.BaseSetOf(t, "explicit2"), 1), 0)
449 require.NoError(t, auth.Save(user))
450
451 err = auth.InvalidateChannels("testUser", true, base.ScopeAndCollectionNames{base.NewScopeAndCollectionName("scope1", "collection1")}, 2)
452 assert.NoError(t, err)
453
454 user2, err := auth.GetUser("testUser")
455 assert.NoError(t, err)
456 assert.Equal(t, ch.TimedSet(nil), user2.Channels())
457 assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit2", "derived3", "derived4", "!"), 1), user2.CollectionChannels("scope1", "collection1"))
458}
459
460// Test cases
461// multiple collections

Callers

nothing calls this directly

Calls 15

TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
NewTestAuthenticatorFunction · 0.85
NewUserMethod · 0.80
SaveMethod · 0.80
InvalidateChannelsMethod · 0.80
GetUserMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected