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

Function TestPutRevisionCacheAttachmentProperty

db/revision_cache_test.go:693–733  ·  view source on GitHub ↗

Ensure attachment properties aren't being incorrectly stored in revision cache body when inserted via Put

(t *testing.T)

Source from the content-addressed store, hash-verified

691
692// Ensure attachment properties aren't being incorrectly stored in revision cache body when inserted via Put
693func TestPutRevisionCacheAttachmentProperty(t *testing.T) {
694
695 base.SetUpTestLogging(t, base.LevelInfo, base.KeyAll)
696
697 db, ctx := setupTestDB(t)
698 defer db.Close(ctx)
699 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
700
701 rev1body := Body{
702 "value": 1234,
703 BodyAttachments: map[string]interface{}{"myatt": map[string]interface{}{"content_type": "text/plain", "data": "SGVsbG8gV29ybGQh"}},
704 }
705 rev1key := "doc1"
706 rev1id, _, err := collection.Put(ctx, rev1key, rev1body)
707 assert.NoError(t, err, "Unexpected error calling collection.Put")
708
709 // Get the raw document directly from the bucket, validate _attachments property isn't found
710 var bucketBody Body
711 _, err = collection.dataStore.Get(rev1key, &bucketBody)
712 assert.NoError(t, err, "Unexpected error calling bucket.Get")
713 _, ok := bucketBody[BodyAttachments]
714 assert.False(t, ok, "_attachments property still present in document body retrieved from bucket: %#v", bucketBody)
715
716 // Get the raw document directly from the revcache, validate _attachments property isn't found
717 docRevision, ok := collection.revisionCache.Peek(ctx, rev1key, rev1id)
718 assert.True(t, ok)
719 assert.NotContains(t, docRevision.BodyBytes, BodyAttachments, "_attachments property still present in document body retrieved from rev cache: %#v", bucketBody)
720 _, ok = docRevision.Attachments["myatt"]
721 assert.True(t, ok, "'myatt' not found in revcache attachments metadata")
722
723 // db.getRev stamps _attachments back in from revcache Attachment metadata
724 body, err := collection.Get1xRevBody(ctx, rev1key, rev1id, false, nil)
725 assert.NoError(t, err, "Unexpected error calling collection.Get1xRevBody")
726 atts, ok := body[BodyAttachments]
727 assert.True(t, ok, "_attachments property was not stamped back in body during collection.Get1xRevBody: %#v", body)
728
729 attsMap, ok := atts.(AttachmentsMeta)
730 require.True(t, ok)
731 _, ok = attsMap["myatt"]
732 assert.True(t, ok, "'myatt' not found in attachment map")
733}
734
735// Ensure attachment properties aren't being incorrectly stored in revision cache body when inserted via PutExistingRev
736func TestPutExistingRevRevisionCacheAttachmentProperty(t *testing.T) {

Callers

nothing calls this directly

Calls 8

SetUpTestLoggingFunction · 0.92
setupTestDBFunction · 0.85
Get1xRevBodyMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.65
PeekMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected