File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -45,3 +45,12 @@ func (bl BlobList) WithPrefix(prefix string) (blobs BlobList) {
4545 }
4646 return blobs
4747}
48+
49+ // Size returns the total size of all blobs in the BlobList
50+ func (bl BlobList ) Size () int64 {
51+ var size int64
52+ for _ , b := range bl {
53+ size += b .Size
54+ }
55+ return size
56+ }
Original file line number Diff line number Diff line change 1+ package simpleblob
2+
3+ import (
4+ "testing"
5+
6+ "github.com/stretchr/testify/assert"
7+ )
8+
9+ func TestBlobListStats (t * testing.T ) {
10+ // Empty BlobList
11+ var blobs BlobList
12+ assert .Equal (t , blobs .Len (), 0 )
13+ assert .Equal (t , blobs .Size (), int64 (0 ))
14+
15+ // Non-empty BlobList
16+ blobs = append (blobs , Blob {
17+ Name : "blob1" ,
18+ Size : 100 ,
19+ }, Blob {
20+ Name : "blob2" ,
21+ Size : 200 ,
22+ })
23+ assert .Equal (t , blobs .Len (), 2 )
24+ assert .Equal (t , blobs .Size (), int64 (300 ))
25+ }
You can’t perform that action at this time.
0 commit comments