Skip to content

Commit 2d5a347

Browse files
authored
Merge pull request #68 from nvaatstra/bloblist-size
Size function for BlobList
2 parents 3666dc4 + 09c7893 commit 2d5a347

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

blobs.go

+9
Original file line numberDiff line numberDiff 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+
}

blobs_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)