diff options
author | Steve Moyer <smoyer1@selesy.com> | 2023-01-05 22:09:51 -0500 |
---|---|---|
committer | Steve Moyer <smoyer1@selesy.com> | 2023-01-05 22:09:51 -0500 |
commit | 5c45e70aabd19502d7fbd2a2b564c5845b41aaa8 (patch) | |
tree | 9e340fe497a6955358e861b36dbcb1966c32cd63 /cache/repo_cache_test.go | |
parent | 0f12b901e7856ae001e960bbd3afc4cbff98ffb7 (diff) | |
download | git-bug-5c45e70aabd19502d7fbd2a2b564c5845b41aaa8.tar.gz |
chore(TestCache): cleanup per PR review
Resolves #979
Diffstat (limited to 'cache/repo_cache_test.go')
-rw-r--r-- | cache/repo_cache_test.go | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go index 3ad64f29..042498df 100644 --- a/cache/repo_cache_test.go +++ b/cache/repo_cache_test.go @@ -18,6 +18,17 @@ import ( func TestCache(t *testing.T) { repo := repository.CreateGoGitTestRepo(t, false) + indexCount := func(t *testing.T, name string) uint64 { + t.Helper() + + idx, err := repo.GetIndex(name) + require.NoError(t, err) + count, err := idx.DocCount() + require.NoError(t, err) + + return count + } + var ( cache *RepoCache bug1 *BugCache @@ -25,8 +36,8 @@ func TestCache(t *testing.T) { ) t.Run("entity operations on cache", func(t *testing.T) { - cache = createTestRepoCacheNoEvents(t, repo) - var err error + cache, err := NewRepoCacheNoEvents(repo) + require.NoError(t, err) // Create, set and get user identity iden1, err = cache.Identities().New("René Descartes", "rene@descartes.fr") @@ -48,8 +59,8 @@ func TestCache(t *testing.T) { require.Len(t, cache.Identities().AllIds(), 2) require.Len(t, cache.identities.excerpts, 2) require.Len(t, cache.identities.cached, 2) - require.Equal(t, uint64(2), indexCount(t, repo, identity.Namespace)) - require.Equal(t, uint64(0), indexCount(t, repo, bug.Namespace)) + require.Equal(t, uint64(2), indexCount(t, identity.Namespace)) + require.Equal(t, uint64(0), indexCount(t, bug.Namespace)) // Create a bug bug1, _, err = cache.Bugs().New("title", "message") @@ -66,8 +77,8 @@ func TestCache(t *testing.T) { require.Len(t, cache.Bugs().AllIds(), 2) require.Len(t, cache.bugs.excerpts, 2) require.Len(t, cache.bugs.cached, 2) - require.Equal(t, uint64(2), indexCount(t, repo, identity.Namespace)) - require.Equal(t, uint64(2), indexCount(t, repo, bug.Namespace)) + require.Equal(t, uint64(2), indexCount(t, identity.Namespace)) + require.Equal(t, uint64(2), indexCount(t, bug.Namespace)) // Resolving _, err = cache.Identities().Resolve(iden1.Id()) @@ -96,13 +107,22 @@ func TestCache(t *testing.T) { res, err = cache.Bugs().Query(q) require.NoError(t, err) require.Len(t, res, 1) + + // Close + require.NoError(t, cache.Close()) + require.Empty(t, cache.bugs.cached) + require.Empty(t, cache.bugs.excerpts) + require.Empty(t, cache.identities.cached) + require.Empty(t, cache.identities.excerpts) }) - // Close (repository is closed by t.Cleanup() when the function above is exited) - require.Empty(t, cache.bugs.cached) - require.Empty(t, cache.bugs.excerpts) - require.Empty(t, cache.identities.cached) - require.Empty(t, cache.identities.excerpts) + t.Run("closed caches are empty", func(t *testing.T) { + t.Skip() + cache, err := NewRepoCacheNoEvents(repo) + require.NoError(t, err) + + require.Empty(t, cache.identities.excerpts) + }) // Reload, only excerpt are loaded, but as we need to load the identities used in the bugs // to check the signatures, we also load the identity used above @@ -112,8 +132,8 @@ func TestCache(t *testing.T) { require.Len(t, cache.bugs.excerpts, 2) require.Len(t, cache.identities.cached, 0) require.Len(t, cache.identities.excerpts, 2) - require.Equal(t, uint64(2), indexCount(t, repo, identity.Namespace)) - require.Equal(t, uint64(2), indexCount(t, repo, bug.Namespace)) + require.Equal(t, uint64(2), indexCount(t, identity.Namespace)) + require.Equal(t, uint64(2), indexCount(t, bug.Namespace)) // Resolving load from the disk _, err := cache.Identities().Resolve(iden1.Id()) |