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

Function TestAttachmentReadStoredInXattr

db/document_test.go:628–675  ·  view source on GitHub ↗

TestAttachmentReadStoredInXattr tests reads legacy format for attachments being stored in sync data xattr as well as testing the new location for attachments in global xattr

(t *testing.T)

Source from the content-addressed store, hash-verified

626// TestAttachmentReadStoredInXattr tests reads legacy format for attachments being stored in sync data xattr as well as
627// testing the new location for attachments in global xattr
628func TestAttachmentReadStoredInXattr(t *testing.T) {
629 ctx := base.TestCtx(t)
630
631 // unmarshal attachments on sync data
632 testSync := []byte(syncDataWithAttachment)
633 doc, err := unmarshalDocumentWithXattrs(ctx, "doc1", nil, testSync, nil, nil, nil, nil, nil, 1, DocUnmarshalSync)
634 require.NoError(t, err)
635
636 // assert on attachments
637 atts := doc.Attachments()
638 assert.Len(t, atts, 2)
639 hello := atts["hello.txt"].(map[string]interface{})
640 assert.Equal(t, "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", hello["digest"])
641 assert.Equal(t, float64(11), hello["length"])
642 assert.Equal(t, float64(1), hello["revpos"])
643 assert.Equal(t, float64(2), hello["ver"])
644 assert.True(t, hello["stub"].(bool))
645
646 bye := atts["bye.txt"].(map[string]interface{})
647 assert.Equal(t, "sha1-l+N7VpXGnoxMm8xfvtWPbz2YvDc=", bye["digest"])
648 assert.Equal(t, float64(19), bye["length"])
649 assert.Equal(t, float64(1), bye["revpos"])
650 assert.Equal(t, float64(2), bye["ver"])
651 assert.True(t, bye["stub"].(bool))
652
653 // unmarshal attachments on global data
654 testGlobal := []byte(globalXattr)
655 sync_meta_no_attachments := []byte(doc_meta_no_vv)
656 doc, err = unmarshalDocumentWithXattrs(ctx, "doc1", nil, sync_meta_no_attachments, nil, nil, nil, nil, testGlobal, 1, DocUnmarshalSync)
657 require.NoError(t, err)
658
659 // assert on attachments
660 atts = doc.Attachments()
661 assert.Len(t, atts, 2)
662 hello = atts["hello.txt"].(map[string]interface{})
663 assert.Equal(t, "sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=", hello["digest"])
664 assert.Equal(t, float64(11), hello["length"])
665 assert.Equal(t, float64(1), hello["revpos"])
666 assert.Equal(t, float64(2), hello["ver"])
667 assert.True(t, hello["stub"].(bool))
668
669 bye = atts["bye.txt"].(map[string]interface{})
670 assert.Equal(t, "sha1-l+N7VpXGnoxMm8xfvtWPbz2YvDc=", bye["digest"])
671 assert.Equal(t, float64(19), bye["length"])
672 assert.Equal(t, float64(1), bye["revpos"])
673 assert.Equal(t, float64(2), bye["ver"])
674 assert.True(t, bye["stub"].(bool))
675}
676
677func TestAlignRevTreeHistory(t *testing.T) {
678 testCases := []struct {

Callers

nothing calls this directly

Calls 5

TestCtxFunction · 0.92
AttachmentsMethod · 0.80
LenMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected