fs/cache: add Entries() for finding how many entries in the fscache #4811

This commit is contained in:
Nick Craig-Wood 2020-11-29 11:25:51 +00:00
parent ebd9462ea6
commit feaaca4987
2 changed files with 18 additions and 0 deletions

5
fs/cache/cache.go vendored
View File

@ -128,3 +128,8 @@ func Put(fsString string, f fs.Fs) {
func Clear() {
c.Clear()
}
// Entries returns the number of entries in the cache
func Entries() int {
return c.Entries()
}

View File

@ -180,3 +180,16 @@ func TestClear(t *testing.T) {
assert.Equal(t, 0, c.Entries())
}
func TestEntries(t *testing.T) {
cleanup, create := mockNewFs(t)
defer cleanup()
assert.Equal(t, 0, Entries())
// Create something
_, err := GetFn(context.Background(), "mock:/", create)
require.NoError(t, err)
assert.Equal(t, 1, Entries())
}