Skip to content

Commit 28fd96e

Browse files
committed
[FAB-13151] Fill in Length fields in attachments
ReadDoc function misses out setting the Length field in the attachments in CouchDoc struct Change-Id: Ife6d4206cf428031ab00392dd90a34e4404325d9 Signed-off-by: ChanderG <mail@chandergovind.org>
1 parent 4c7ffa3 commit 28fd96e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

core/ledger/util/couchdb/couchdb.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error) {
823823

824824
logger.Debugf("[%s] Retrieved attachment data", dbclient.DBName)
825825
attachment.AttachmentBytes = respBody
826+
attachment.Length = uint64(len(attachment.AttachmentBytes))
826827
attachment.Name = p.FileName()
827828
attachments = append(attachments, attachment)
828829

@@ -835,6 +836,7 @@ func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error) {
835836
}
836837
logger.Debugf("[%s] Retrieved attachment data", dbclient.DBName)
837838
attachment.AttachmentBytes = partdata
839+
attachment.Length = uint64(len(attachment.AttachmentBytes))
838840
attachment.Name = p.FileName()
839841
attachments = append(attachments, attachment)
840842

core/ledger/util/couchdb/couchdb_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ func TestDBSaveAttachment(t *testing.T) {
742742
attachment := &AttachmentInfo{}
743743
attachment.AttachmentBytes = byteText
744744
attachment.ContentType = "text/plain"
745+
attachment.Length = uint64(len(byteText))
745746
attachment.Name = "valueBytes"
746747

747748
attachments := []*AttachmentInfo{}
@@ -766,6 +767,7 @@ func TestDBSaveAttachment(t *testing.T) {
766767
assert.NoError(t, geterr2, "Error when trying to retrieve a document with attachment")
767768
assert.NotNil(t, couchDoc.Attachments)
768769
assert.Equal(t, byteText, couchDoc.Attachments[0].AttachmentBytes)
770+
assert.Equal(t, attachment.Length, couchDoc.Attachments[0].Length)
769771

770772
}
771773

0 commit comments

Comments
 (0)