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

Function TestUpdatePrincipal

db/database_test.go:1860–1894  ·  view source on GitHub ↗

Unit test for bug #673

(t *testing.T)

Source from the content-addressed store, hash-verified

1858
1859// Unit test for bug #673
1860func TestUpdatePrincipal(t *testing.T) {
1861 base.SetUpTestLogging(t, base.LevelDebug, base.KeyCache, base.KeyChanges)
1862
1863 // use default collection based on use of GetPrincipalForTest
1864 db, ctx := setupTestDBDefaultCollection(t)
1865 defer db.Close(ctx)
1866
1867 // Create a user with access to channel ABC
1868 authenticator := db.Authenticator(ctx)
1869 user, err := authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "ABC"))
1870 require.NoError(t, err)
1871 assert.NoError(t, authenticator.Save(user))
1872
1873 // Validate that a call to UpdatePrincipals with no changes to the user doesn't allocate a sequence
1874 userInfo, err := db.GetPrincipalForTest(t, "naomi", true)
1875 require.NoError(t, err)
1876 userInfo.ExplicitChannels = base.SetOf("ABC")
1877 _, _, err = db.UpdatePrincipal(ctx, userInfo, true, true)
1878 assert.NoError(t, err, "Unable to update principal")
1879
1880 nextSeq, err := db.sequences.nextSequence(ctx)
1881 require.NoError(t, err)
1882 assert.Equal(t, uint64(1), nextSeq)
1883
1884 // Validate that a call to UpdatePrincipals with changes to the user does allocate a sequence
1885 userInfo, err = db.GetPrincipalForTest(t, "naomi", true)
1886 require.NoError(t, err)
1887 userInfo.ExplicitChannels = base.SetOf("ABC", "PBS")
1888 _, _, err = db.UpdatePrincipal(ctx, userInfo, true, true)
1889 assert.NoError(t, err, "Unable to update principal")
1890
1891 nextSeq, err = db.sequences.nextSequence(ctx)
1892 require.NoError(t, err)
1893 assert.Equal(t, uint64(3), nextSeq)
1894}
1895
1896func TestUpdatePrincipalCASRetry(t *testing.T) {
1897 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAuth, base.KeyCRUD)

Callers

nothing calls this directly

Calls 12

SetUpTestLoggingFunction · 0.92
BaseSetOfFunction · 0.92
SetOfFunction · 0.92
NewUserMethod · 0.80
SaveMethod · 0.80
GetPrincipalForTestMethod · 0.80
UpdatePrincipalMethod · 0.80
nextSequenceMethod · 0.80
CloseMethod · 0.65
AuthenticatorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected