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

Function TestChangesIncludeDocs

rest/changestest/changes_api_test.go:1758–1933  ·  view source on GitHub ↗

Validate retrieval of various document body types using include_docs.

(t *testing.T)

Source from the content-addressed store, hash-verified

1756
1757// Validate retrieval of various document body types using include_docs.
1758func TestChangesIncludeDocs(t *testing.T) {
1759 base.SetUpTestLogging(t, base.LevelInfo, base.KeyNone)
1760
1761 rtConfig := rest.RestTesterConfig{SyncFn: `function(doc) {channel(doc.channels)}`}
1762 rt := rest.NewRestTester(t, &rtConfig)
1763 testDB := rt.GetDatabase()
1764 testDB.RevsLimit = 3
1765 rt.GetDatabase().EnableAllowConflicts(rt.TB())
1766 defer rt.Close()
1767 collection, ctx := rt.GetSingleTestDatabaseCollection()
1768
1769 rt.CreateUser("user1", []string{"alpha", "beta"})
1770
1771 // Create docs for each scenario
1772 // Active
1773 _, err := updateTestDoc(rt, "doc_active", "", `{"type": "active", "channels":["alpha"]}`)
1774 assert.NoError(t, err, "Error updating doc")
1775
1776 // Multi-revision
1777 var revid string
1778 revid, err = updateTestDoc(rt, "doc_multi_rev", "", `{"type": "active", "channels":["alpha"], "v":1}`)
1779 assert.NoError(t, err, "Error updating doc")
1780 _, err = updateTestDoc(rt, "doc_multi_rev", revid, `{"type": "active", "channels":["alpha"], "v":2}`)
1781 assert.NoError(t, err, "Error updating doc")
1782
1783 // Tombstoned
1784 revid, err = updateTestDoc(rt, "doc_tombstone", "", `{"type": "tombstone", "channels":["alpha"]}`)
1785 assert.NoError(t, err, "Error updating doc")
1786 response := rt.SendAdminRequest("DELETE", fmt.Sprintf("/{{.keyspace}}/doc_tombstone?rev=%s", revid), "")
1787 rest.RequireStatus(t, response, 200)
1788
1789 // Removed
1790 revid, err = updateTestDoc(rt, "doc_removed", "", `{"type": "removed", "channels":["alpha"]}`)
1791 assert.NoError(t, err, "Error updating doc")
1792 _, err = updateTestDoc(rt, "doc_removed", revid, `{"type": "removed"}`)
1793 assert.NoError(t, err, "Error updating doc")
1794
1795 // No access (no channels)
1796 _, err = updateTestDoc(rt, "doc_no_channels", "", `{"type": "no_channels", "channels":["gamma"]}`)
1797 assert.NoError(t, err, "Error updating doc")
1798
1799 // No access (other channels)
1800 _, err = updateTestDoc(rt, "doc_no_access", "", `{"type": "no_access", "channels":["gamma"]}`)
1801 assert.NoError(t, err, "Error updating doc")
1802
1803 // Removal, pruned from rev tree
1804 var prunedRevId string
1805 prunedRevId, err = updateTestDoc(rt, "doc_pruned", "", `{"type": "pruned", "channels":["alpha"]}`)
1806 assert.NoError(t, err, "Error updating doc")
1807 // Generate more revs than revs_limit (3)
1808 revid = prunedRevId
1809 for i := 0; i < 5; i++ {
1810 docVersion := rt.UpdateDoc("doc_pruned", db.DocVersion{RevTreeID: revid}, `{"type": "pruned", "channels":["gamma"]}`)
1811 revid = docVersion.RevTreeID
1812 }
1813
1814 // Doc w/ attachment
1815 revid, err = updateTestDoc(rt, "doc_attachment", "", `{"type": "attachments", "channels":["alpha"]}`)

Callers

nothing calls this directly

Calls 15

GetDatabaseMethod · 0.95
TBMethod · 0.95
CloseMethod · 0.95
CreateUserMethod · 0.95
SendAdminRequestMethod · 0.95
UpdateDocMethod · 0.95
WaitForPendingChangesMethod · 0.95
GetChangesMethod · 0.95
UnmarshalMethod · 0.95
SetUpTestLoggingFunction · 0.92

Tested by

no test coverage detected