Repro attempt for SG #3281 - Set up a user w/ access to channel A - Write two revision of a document (both in channel A) - Write two more revisions of the document, no longer in channel A - Have the user issue a rev request for rev 3. Expected: - Users gets a removed:true response Actual: - Same
(t *testing.T)
| 1826 | // Actual: |
| 1827 | // - Same as Expected (this test is unable to repro SG #3281, but is being left in as a regression test) |
| 1828 | func TestGetRemovedDoc(t *testing.T) { |
| 1829 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 1830 | |
| 1831 | rt := NewRestTester(t, &RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction}) |
| 1832 | defer rt.Close() |
| 1833 | const ( |
| 1834 | user1 = "user1" |
| 1835 | user2 = "user2" |
| 1836 | ) |
| 1837 | rt.CreateUser(user1, []string{user1}) |
| 1838 | rt.CreateUser(user2, []string{user1}) |
| 1839 | btSpec := BlipTesterSpec{ |
| 1840 | connectingUsername: user1, |
| 1841 | blipProtocols: []string{db.CBMobileReplicationV2.SubprotocolString()}, |
| 1842 | } |
| 1843 | bt := NewBlipTesterFromSpecWithRT(rt, &btSpec) |
| 1844 | defer bt.Close() |
| 1845 | |
| 1846 | // Workaround data race (https://gist.github.com/tleyden/0ace70b8a38b76a7beee95529610b6cf) that happens because |
| 1847 | // there are multiple goroutines accessing the bt.blipContext.HandlerForProfile map. |
| 1848 | // The workaround uses a separate blipTester, and therefore a separate context. It uses a different |
| 1849 | // user to avoid an error when the NewBlipTesterFromSpec tries to create the user (eg, user1 already exists error) |
| 1850 | btSpec2 := BlipTesterSpec{ |
| 1851 | connectingUsername: user1, |
| 1852 | blipProtocols: []string{db.CBMobileReplicationV2.SubprotocolString()}, |
| 1853 | } |
| 1854 | bt2 := NewBlipTesterFromSpecWithRT(rt, &btSpec2) |
| 1855 | defer bt2.Close() |
| 1856 | |
| 1857 | // Add rev-1 in channel user1 |
| 1858 | sent, _, resp, err := bt.SendRev("foo", "1-abc", []byte(`{"key": "val", "channels": ["user1"]}`), blip.Properties{}) |
| 1859 | assert.True(t, sent) |
| 1860 | require.NoError(t, err) // no error |
| 1861 | assert.Empty(t, resp.Properties["Error-Code"]) // no error |
| 1862 | |
| 1863 | // Add rev-2 in channel user1 |
| 1864 | history := []string{"1-abc"} |
| 1865 | sent, _, resp, err = bt.SendRevWithHistory("foo", "2-bcd", history, []byte(`{"key": "val", "channels": ["user1"]}`), blip.Properties{"noconflicts": "true"}) |
| 1866 | assert.True(t, sent) |
| 1867 | require.NoError(t, err) // no error |
| 1868 | assert.Empty(t, resp.Properties["Error-Code"]) // no error |
| 1869 | |
| 1870 | // wait for rev 2 to arrive to cache cache |
| 1871 | rt.WaitForPendingChanges() |
| 1872 | |
| 1873 | // Try to get rev 2 via BLIP API and assert that _removed == false |
| 1874 | resultDoc, err := bt.GetDocAtRev("foo", "2-bcd") |
| 1875 | require.NoError(t, err, "Unexpected Error") |
| 1876 | assert.False(t, resultDoc.IsRemoved()) |
| 1877 | |
| 1878 | // Add rev-3, remove from channel user1 and put into channel another_channel |
| 1879 | history = []string{"2-bcd", "1-abc"} |
| 1880 | sent, _, resp, err = bt.SendRevWithHistory("foo", "3-cde", history, []byte(`{"key": "val", "channels": ["another_channel"]}`), blip.Properties{"noconflicts": "true"}) |
| 1881 | assert.True(t, sent) |
| 1882 | assert.NoError(t, err) // no error |
| 1883 | assert.Empty(t, resp.Properties["Error-Code"]) // no error |
| 1884 | |
| 1885 | // Add rev-4, keeping it in channel another_channel |
nothing calls this directly
no test coverage detected