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

Function TestRebuildUserChannelsMultiCollection

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

Source from the content-addressed store, hash-verified

402}
403
404func TestRebuildUserChannelsMultiCollection(t *testing.T) {
405 ctx := base.TestCtx(t)
406 bucket := base.GetTestBucket(t)
407 defer bucket.Close(ctx)
408 dataStore := bucket.GetSingleDataStore()
409 computer := mockComputer{}
410 computer.AddChannelsForCollection(base.DefaultScope, base.DefaultCollection, ch.AtSequence(ch.BaseSetOf(t, "derived1", "derived2"), 1))
411 computer.AddChannelsForCollection("scope1", "collection1", ch.AtSequence(ch.BaseSetOf(t, "derived3", "derived4"), 1))
412
413 options := DefaultAuthenticatorOptions(ctx)
414 options.Collections = map[string]map[string]struct{}{
415 base.DefaultScope: {base.DefaultCollection: struct{}{}},
416 "scope1": {"collection1": struct{}{}},
417 }
418 auth := NewTestAuthenticator(t, dataStore, &computer, options)
419 user, _ := auth.NewUser("testUser", "password", ch.BaseSetOf(t, "explicit1"))
420 user.SetCollectionExplicitChannels("scope1", "collection1", ch.AtSequence(ch.BaseSetOf(t, "explicit2"), 1), 0)
421 err := auth.Save(user)
422 assert.NoError(t, err)
423
424 err = auth.InvalidateChannels("testUser", true, base.ScopeAndCollectionNames{base.NewScopeAndCollectionName("scope1", "collection1")}, 2)
425 assert.NoError(t, err)
426
427 user2, err := auth.GetUser("testUser")
428 assert.NoError(t, err)
429 assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit1", "derived1", "derived2", "!"), 1), user2.Channels())
430 assert.Equal(t, ch.AtSequence(ch.BaseSetOf(t, "explicit2", "derived3", "derived4", "!"), 1), user2.CollectionChannels("scope1", "collection1"))
431}
432
433func TestRebuildUserChannelsNamedCollection(t *testing.T) {
434 ctx := base.TestCtx(t)

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