Skip to content

Commit

Permalink
Merge pull request #68 from nvaatstra/bloblist-size
Browse files Browse the repository at this point in the history
Size function for BlobList
  • Loading branch information
wojas authored Feb 22, 2024
2 parents 3666dc4 + 09c7893 commit 2d5a347
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ func (bl BlobList) WithPrefix(prefix string) (blobs BlobList) {
}
return blobs
}

// Size returns the total size of all blobs in the BlobList
func (bl BlobList) Size() int64 {
var size int64
for _, b := range bl {
size += b.Size
}
return size
}
25 changes: 25 additions & 0 deletions blobs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package simpleblob

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestBlobListStats(t *testing.T) {
// Empty BlobList
var blobs BlobList
assert.Equal(t, blobs.Len(), 0)
assert.Equal(t, blobs.Size(), int64(0))

// Non-empty BlobList
blobs = append(blobs, Blob{
Name: "blob1",
Size: 100,
}, Blob{
Name: "blob2",
Size: 200,
})
assert.Equal(t, blobs.Len(), 2)
assert.Equal(t, blobs.Size(), int64(300))
}

0 comments on commit 2d5a347

Please sign in to comment.