Skip to content

Commit

Permalink
[FAB-13151] Fill in Length fields in attachments
Browse files Browse the repository at this point in the history
ReadDoc function misses out setting the Length field in the
attachments in CouchDoc struct

Change-Id: Ife6d4206cf428031ab00392dd90a34e4404325d9
Signed-off-by: ChanderG <mail@chandergovind.org>
  • Loading branch information
ChanderG committed Dec 4, 2018
1 parent 4c7ffa3 commit 28fd96e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/ledger/util/couchdb/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ func (dbclient *CouchDatabase) ReadDoc(id string) (*CouchDoc, string, error) {

logger.Debugf("[%s] Retrieved attachment data", dbclient.DBName)
attachment.AttachmentBytes = respBody
attachment.Length = uint64(len(attachment.AttachmentBytes))
attachment.Name = p.FileName()
attachments = append(attachments, attachment)

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

Expand Down
2 changes: 2 additions & 0 deletions core/ledger/util/couchdb/couchdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ func TestDBSaveAttachment(t *testing.T) {
attachment := &AttachmentInfo{}
attachment.AttachmentBytes = byteText
attachment.ContentType = "text/plain"
attachment.Length = uint64(len(byteText))
attachment.Name = "valueBytes"

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

}

Expand Down

0 comments on commit 28fd96e

Please sign in to comment.