Unit test for bug #673
(t *testing.T)
| 1858 | |
| 1859 | // Unit test for bug #673 |
| 1860 | func 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 | |
| 1896 | func TestUpdatePrincipalCASRetry(t *testing.T) { |
| 1897 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAuth, base.KeyCRUD) |
nothing calls this directly
no test coverage detected