add test for DiskStore.list()

This commit is contained in:
Alex Grintsvayg 2020-10-26 12:27:27 -04:00
parent 3608971f0b
commit 7a3225434e
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
2 changed files with 26 additions and 1 deletions

View file

@ -117,8 +117,13 @@ func (d *DiskStore) Delete(hash string) error {
return errors.Err(err)
}
// list returns a slice of blobs that already exist in the blobDir
// list returns the hashes of blobs that already exist in the blobDir
func (d *DiskStore) list() ([]string, error) {
err := d.initOnce()
if err != nil {
return nil, err
}
dirs, err := afero.ReadDir(d.fs, d.blobDir)
if err != nil {
return nil, err

View file

@ -119,3 +119,23 @@ func TestLRUStore_UnderlyingBlobMissing(t *testing.T) {
// lru.Get() removes hash if underlying store doesn't have it
assert.False(t, lru.lru.Contains(hash))
}
func TestLRUStore_loadExisting(t *testing.T) {
d := NewDiskStore("/", 2)
d.fs = afero.NewMemMapFs()
hash := "hash"
b := []byte("this is a blob of stuff")
err := d.Put(hash, b)
require.NoError(t, err)
existing, err := d.list()
require.NoError(t, err)
require.Equal(t, 1, len(existing), "blob should exist in cache")
assert.Equal(t, hash, existing[0])
lru := NewLRUStore(d, 3) // lru should load existing blobs when it's created
has, err := lru.Has(hash)
require.NoError(t, err)
assert.True(t, has, "hash should be loaded from disk store but it's not")
}