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

Function TestGetDeleted

db/database_test.go:724–762  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

722}
723
724func TestGetDeleted(t *testing.T) {
725
726 db, ctx := setupTestDB(t)
727 defer db.Close(ctx)
728 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
729
730 body := Body{"key1": 1234}
731 rev1id, _, err := collection.Put(ctx, "doc1", body)
732 assert.NoError(t, err, "Put")
733
734 rev2id, _, err := collection.DeleteDoc(ctx, "doc1", DocVersion{RevTreeID: rev1id})
735 assert.NoError(t, err, "DeleteDoc")
736
737 // Get the deleted doc with its history; equivalent to GET with ?revs=true
738 body, err = collection.Get1xRevBody(ctx, "doc1", rev2id, true, nil)
739 assert.NoError(t, err, "Get1xRevBody")
740 expectedResult := Body{
741 BodyId: "doc1",
742 BodyRev: rev2id,
743 BodyDeleted: true,
744 BodyRevisions: Revisions{RevisionsStart: 2, RevisionsIds: []string{"bc6d97f6e97c0d034a34f8aac2bf8b44", "dfd5e19813767eeddd08270fc5f385cd"}},
745 }
746 AssertEqualBodies(t, expectedResult, body)
747
748 // Get the raw doc and make sure the sync data has the current revision
749 doc, err := collection.GetDocument(ctx, "doc1", DocUnmarshalAll)
750 assert.NoError(t, err, "Err getting doc")
751 assert.Equal(t, rev2id, doc.SyncData.GetRevTreeID())
752
753 // Try again but with a user who doesn't have access to this revision (see #179)
754 authenticator := auth.NewAuthenticator(db.MetadataStore, db, db.AuthenticatorOptions(ctx))
755 collection.user, err = authenticator.GetUser("")
756 assert.NoError(t, err, "GetUser")
757 collection.user.SetExplicitChannels(nil, 1)
758
759 body, err = collection.Get1xRevBody(ctx, "doc1", rev2id, true, nil)
760 assert.NoError(t, err, "Get1xRevBody")
761 AssertEqualBodies(t, expectedResult, body)
762}
763
764// Test retrieval of a channel removal revision, when the revision is not otherwise available
765func TestGetRemovedAsUser(t *testing.T) {

Callers

nothing calls this directly

Calls 14

GetUserMethod · 0.95
NewAuthenticatorFunction · 0.92
setupTestDBFunction · 0.85
AssertEqualBodiesFunction · 0.85
Get1xRevBodyMethod · 0.80
AuthenticatorOptionsMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.65
GetDocumentMethod · 0.65
SetExplicitChannelsMethod · 0.65
DeleteDocMethod · 0.45

Tested by

no test coverage detected