From feaaca4987324822bd6d6b6b0756481e7f32b8a0 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 29 Nov 2020 11:25:51 +0000 Subject: [PATCH] fs/cache: add Entries() for finding how many entries in the fscache #4811 --- fs/cache/cache.go | 5 +++++ fs/cache/cache_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/fs/cache/cache.go b/fs/cache/cache.go index dcc94adff..961dd3c7d 100644 --- a/fs/cache/cache.go +++ b/fs/cache/cache.go @@ -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() +} diff --git a/fs/cache/cache_test.go b/fs/cache/cache_test.go index ca5128aa6..8f35ebd89 100644 --- a/fs/cache/cache_test.go +++ b/fs/cache/cache_test.go @@ -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()) +}