2019-03-25 23:58:27 +03:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2021-03-29 11:08:57 +03:00
|
|
|
"strings"
|
2019-03-25 23:58:27 +03:00
|
|
|
"testing"
|
2021-03-29 11:08:57 +03:00
|
|
|
"time"
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2020-07-26 11:14:11 +03:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-03-25 23:58:27 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-05-27 22:14:55 +03:00
|
|
|
|
2022-12-23 01:19:31 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entities/bug"
|
|
|
|
"github.com/MichaelMure/git-bug/entities/identity"
|
2022-11-19 13:33:12 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2020-03-14 18:47:38 +03:00
|
|
|
"github.com/MichaelMure/git-bug/query"
|
2019-05-27 22:14:55 +03:00
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2019-03-25 23:58:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
2022-06-16 16:02:52 +03:00
|
|
|
repo := repository.CreateGoGitTestRepo(t, false)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-06 06:09:51 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
cache, err := NewRepoCacheNoEvents(repo)
|
|
|
|
require.NoError(t, err)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// Create, set and get user identity
|
|
|
|
iden1, err := cache.Identities().New("René Descartes", "rene@descartes.fr")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = cache.SetUserIdentity(iden1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
userIden, err := cache.GetUserIdentity()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, iden1.Id(), userIden.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// it's possible to create two identical identities
|
|
|
|
iden2, err := cache.Identities().New("René Descartes", "rene@descartes.fr")
|
|
|
|
require.NoError(t, err)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// Two identical identities yield a different id
|
|
|
|
require.NotEqual(t, iden1.Id(), iden2.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// There is now two identities in the cache
|
|
|
|
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, identity.Namespace))
|
|
|
|
require.Equal(t, uint64(0), indexCount(t, bug.Namespace))
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// Create a bug
|
|
|
|
bug1, _, err := cache.Bugs().New("title", "message")
|
|
|
|
require.NoError(t, err)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// It's possible to create two identical bugs
|
|
|
|
bug2, _, err := cache.Bugs().New("title", "marker")
|
|
|
|
require.NoError(t, err)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// two identical bugs yield a different id
|
|
|
|
require.NotEqual(t, bug1.Id(), bug2.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// There is now two bugs in the cache
|
|
|
|
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, identity.Namespace))
|
|
|
|
require.Equal(t, uint64(2), indexCount(t, bug.Namespace))
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// Resolving
|
|
|
|
_, err = cache.Identities().Resolve(iden1.Id())
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = cache.Identities().ResolveExcerpt(iden1.Id())
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = cache.Identities().ResolvePrefix(iden1.Id().String()[:10])
|
|
|
|
require.NoError(t, err)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
_, err = cache.Bugs().Resolve(bug1.Id())
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = cache.Bugs().ResolveExcerpt(bug1.Id())
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = cache.Bugs().ResolvePrefix(bug1.Id().String()[:10])
|
|
|
|
require.NoError(t, err)
|
2023-01-06 06:09:51 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// Querying
|
|
|
|
q, err := query.Parse("status:open author:descartes sort:edit-asc")
|
|
|
|
require.NoError(t, err)
|
|
|
|
res, err := cache.Bugs().Query(q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, res, 2)
|
2022-12-23 01:19:31 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
q, err = query.Parse("status:open marker") // full-text search
|
|
|
|
require.NoError(t, err)
|
|
|
|
res, err = cache.Bugs().Query(q)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, res, 1)
|
2023-01-06 06:09:51 +03:00
|
|
|
|
2023-01-11 15:19:03 +03:00
|
|
|
// 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)
|
2019-03-25 23:58:27 +03:00
|
|
|
|
2021-04-04 14:28:21 +03:00
|
|
|
// 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
|
2023-01-11 15:19:03 +03:00
|
|
|
cache, err = NewRepoCacheNoEvents(repo)
|
|
|
|
require.NoError(t, err)
|
2023-01-05 01:32:59 +03:00
|
|
|
|
2022-12-22 02:48:00 +03:00
|
|
|
require.Len(t, cache.bugs.cached, 0)
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, cache.bugs.excerpts, 2)
|
|
|
|
require.Len(t, cache.identities.cached, 0)
|
|
|
|
require.Len(t, cache.identities.excerpts, 2)
|
2023-01-06 06:09:51 +03:00
|
|
|
require.Equal(t, uint64(2), indexCount(t, identity.Namespace))
|
|
|
|
require.Equal(t, uint64(2), indexCount(t, bug.Namespace))
|
2019-03-25 23:58:27 +03:00
|
|
|
|
|
|
|
// Resolving load from the disk
|
2023-01-11 15:19:03 +03:00
|
|
|
_, err = cache.Identities().Resolve(iden1.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
_, err = cache.Identities().ResolveExcerpt(iden1.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
_, err = cache.Identities().ResolvePrefix(iden1.Id().String()[:10])
|
2019-03-25 23:58:27 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
_, err = cache.Bugs().Resolve(bug1.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
_, err = cache.Bugs().ResolveExcerpt(bug1.Id())
|
2019-03-25 23:58:27 +03:00
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
_, err = cache.Bugs().ResolvePrefix(bug1.Id().String()[:10])
|
2019-03-25 23:58:27 +03:00
|
|
|
require.NoError(t, err)
|
2023-01-04 04:17:17 +03:00
|
|
|
|
2022-11-26 16:49:59 +03:00
|
|
|
require.Len(t, cache.bugs.cached, 1)
|
|
|
|
require.Len(t, cache.bugs.excerpts, 2)
|
|
|
|
require.Len(t, cache.identities.cached, 1)
|
|
|
|
require.Len(t, cache.identities.excerpts, 2)
|
|
|
|
require.Equal(t, uint64(2), indexCount(t, identity.Namespace))
|
|
|
|
require.Equal(t, uint64(2), indexCount(t, bug.Namespace))
|
|
|
|
|
|
|
|
// Remove + RemoveAll
|
|
|
|
err = cache.Identities().Remove(iden1.Id().String()[:10])
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = cache.Bugs().Remove(bug1.Id().String()[:10])
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, cache.bugs.cached, 0)
|
|
|
|
require.Len(t, cache.bugs.excerpts, 1)
|
|
|
|
require.Len(t, cache.identities.cached, 0)
|
|
|
|
require.Len(t, cache.identities.excerpts, 1)
|
|
|
|
require.Equal(t, uint64(1), indexCount(t, identity.Namespace))
|
|
|
|
require.Equal(t, uint64(1), indexCount(t, bug.Namespace))
|
|
|
|
|
|
|
|
_, err = cache.Identities().New("René Descartes", "rene@descartes.fr")
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, _, err = cache.Bugs().NewRaw(iden2, time.Now().Unix(), "title", "message", nil, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = cache.RemoveAll()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, cache.bugs.cached, 0)
|
|
|
|
require.Len(t, cache.bugs.excerpts, 0)
|
|
|
|
require.Len(t, cache.identities.cached, 0)
|
|
|
|
require.Len(t, cache.identities.excerpts, 0)
|
|
|
|
require.Equal(t, uint64(0), indexCount(t, identity.Namespace))
|
|
|
|
require.Equal(t, uint64(0), indexCount(t, bug.Namespace))
|
|
|
|
|
2023-01-04 04:17:17 +03:00
|
|
|
// 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)
|
2019-03-25 23:58:27 +03:00
|
|
|
}
|
2019-04-02 23:01:42 +03:00
|
|
|
|
2021-02-14 14:38:09 +03:00
|
|
|
func TestCachePushPull(t *testing.T) {
|
2022-06-16 16:02:52 +03:00
|
|
|
repoA, repoB, _ := repository.SetupGoGitReposAndRemote(t)
|
2019-04-02 23:01:42 +03:00
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
cacheA := createTestRepoCacheNoEvents(t, repoA)
|
|
|
|
cacheB := createTestRepoCacheNoEvents(t, repoB)
|
2019-04-02 23:01:42 +03:00
|
|
|
|
|
|
|
// Create, set and get user identity
|
2022-12-21 23:54:36 +03:00
|
|
|
reneA, err := cacheA.Identities().New("René Descartes", "rene@descartes.fr")
|
2019-04-02 23:01:42 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
err = cacheA.SetUserIdentity(reneA)
|
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
isaacB, err := cacheB.Identities().New("Isaac Newton", "isaac@newton.uk")
|
2021-02-14 13:36:32 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
err = cacheB.SetUserIdentity(isaacB)
|
|
|
|
require.NoError(t, err)
|
2019-04-02 23:01:42 +03:00
|
|
|
|
|
|
|
// distribute the identity
|
|
|
|
_, err = cacheA.Push("origin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = cacheB.Pull("origin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Create a bug in A
|
2022-12-21 23:54:36 +03:00
|
|
|
_, _, err = cacheA.Bugs().New("bug1", "message")
|
2019-04-02 23:01:42 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// A --> remote --> B
|
|
|
|
_, err = cacheA.Push("origin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = cacheB.Pull("origin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, cacheB.Bugs().AllIds(), 1)
|
2019-04-02 23:01:42 +03:00
|
|
|
|
|
|
|
// retrieve and set identity
|
2022-12-21 23:54:36 +03:00
|
|
|
reneB, err := cacheB.Identities().Resolve(reneA.Id())
|
2019-04-02 23:01:42 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = cacheB.SetUserIdentity(reneB)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// B --> remote --> A
|
2022-12-21 23:54:36 +03:00
|
|
|
_, _, err = cacheB.Bugs().New("bug2", "message")
|
2019-04-02 23:01:42 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = cacheB.Push("origin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = cacheA.Pull("origin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, cacheA.Bugs().AllIds(), 2)
|
2019-04-02 23:01:42 +03:00
|
|
|
}
|
2020-07-26 11:14:11 +03:00
|
|
|
|
|
|
|
func TestRemove(t *testing.T) {
|
2022-06-16 16:02:52 +03:00
|
|
|
repo := repository.CreateGoGitTestRepo(t, false)
|
|
|
|
remoteA := repository.CreateGoGitTestRepo(t, true)
|
|
|
|
remoteB := repository.CreateGoGitTestRepo(t, true)
|
2020-07-26 11:14:11 +03:00
|
|
|
|
2020-12-05 05:08:54 +03:00
|
|
|
err := repo.AddRemote("remoteA", remoteA.GetLocalRemote())
|
2020-07-26 11:14:11 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-05 05:08:54 +03:00
|
|
|
err = repo.AddRemote("remoteB", remoteB.GetLocalRemote())
|
2020-07-26 11:14:11 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
repoCache := createTestRepoCacheNoEvents(t, repo)
|
2020-07-26 11:14:11 +03:00
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
rene, err := repoCache.Identities().New("René Descartes", "rene@descartes.fr")
|
2020-07-26 11:14:11 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-07-26 10:52:29 +03:00
|
|
|
err = repoCache.SetUserIdentity(rene)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
_, _, err = repoCache.Bugs().New("title", "message")
|
2020-08-25 05:43:42 +03:00
|
|
|
require.NoError(t, err)
|
2020-07-26 11:14:11 +03:00
|
|
|
|
|
|
|
// and one more for testing
|
2022-12-21 23:54:36 +03:00
|
|
|
b1, _, err := repoCache.Bugs().New("title", "message")
|
2020-07-26 11:14:11 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = repoCache.Push("remoteA")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = repoCache.Push("remoteB")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = repoCache.Fetch("remoteA")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = repoCache.Fetch("remoteB")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
err = repoCache.Bugs().Remove(b1.Id().String())
|
2020-07-26 11:14:11 +03:00
|
|
|
require.NoError(t, err)
|
2022-12-21 23:54:36 +03:00
|
|
|
assert.Len(t, repoCache.bugs.cached, 1)
|
|
|
|
assert.Len(t, repoCache.bugs.excerpts, 1)
|
2020-07-28 15:24:04 +03:00
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
_, err = repoCache.Bugs().Resolve(b1.Id())
|
|
|
|
assert.ErrorAs(t, entity.ErrNotFound{}, err)
|
2020-07-26 11:14:11 +03:00
|
|
|
}
|
2020-07-26 10:52:29 +03:00
|
|
|
|
|
|
|
func TestCacheEviction(t *testing.T) {
|
2022-06-16 16:02:52 +03:00
|
|
|
repo := repository.CreateGoGitTestRepo(t, false)
|
2023-01-05 01:32:59 +03:00
|
|
|
repoCache := createTestRepoCacheNoEvents(t, repo)
|
2020-08-25 16:26:23 +03:00
|
|
|
repoCache.setCacheSize(2)
|
2020-07-26 10:52:29 +03:00
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Equal(t, 2, repoCache.bugs.maxLoaded)
|
|
|
|
require.Len(t, repoCache.bugs.cached, 0)
|
|
|
|
require.Equal(t, repoCache.bugs.lru.Len(), 0)
|
2020-07-26 10:52:29 +03:00
|
|
|
|
|
|
|
// Generating some bugs
|
2022-12-21 23:54:36 +03:00
|
|
|
rene, err := repoCache.Identities().New("René Descartes", "rene@descartes.fr")
|
2020-07-26 10:52:29 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
err = repoCache.SetUserIdentity(rene)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
bug1, _, err := repoCache.Bugs().New("title", "message")
|
2020-07-26 10:52:29 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
checkBugPresence(t, repoCache, bug1, true)
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, repoCache.bugs.cached, 1)
|
|
|
|
require.Equal(t, 1, repoCache.bugs.lru.Len())
|
2020-07-26 10:52:29 +03:00
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
bug2, _, err := repoCache.Bugs().New("title", "message")
|
2020-07-26 10:52:29 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
checkBugPresence(t, repoCache, bug1, true)
|
|
|
|
checkBugPresence(t, repoCache, bug2, true)
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, repoCache.bugs.cached, 2)
|
|
|
|
require.Equal(t, 2, repoCache.bugs.lru.Len())
|
2020-07-26 10:52:29 +03:00
|
|
|
|
|
|
|
// Number of bugs should not exceed max size of lruCache, oldest one should be evicted
|
2022-12-21 23:54:36 +03:00
|
|
|
bug3, _, err := repoCache.Bugs().New("title", "message")
|
2020-07-26 10:52:29 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, repoCache.bugs.cached, 2)
|
|
|
|
require.Equal(t, 2, repoCache.bugs.lru.Len())
|
2020-08-25 05:43:42 +03:00
|
|
|
checkBugPresence(t, repoCache, bug1, false)
|
|
|
|
checkBugPresence(t, repoCache, bug2, true)
|
|
|
|
checkBugPresence(t, repoCache, bug3, true)
|
2020-07-26 10:52:29 +03:00
|
|
|
|
|
|
|
// Accessing bug should update position in lruCache and therefore it should not be evicted
|
2022-12-21 23:54:36 +03:00
|
|
|
repoCache.bugs.lru.Get(bug2.Id())
|
|
|
|
oldestId, _ := repoCache.bugs.lru.GetOldest()
|
2020-07-26 10:52:29 +03:00
|
|
|
require.Equal(t, bug3.Id(), oldestId)
|
|
|
|
|
|
|
|
checkBugPresence(t, repoCache, bug1, false)
|
|
|
|
checkBugPresence(t, repoCache, bug2, true)
|
|
|
|
checkBugPresence(t, repoCache, bug3, true)
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Len(t, repoCache.bugs.cached, 2)
|
|
|
|
require.Equal(t, 2, repoCache.bugs.lru.Len())
|
2020-07-26 10:52:29 +03:00
|
|
|
}
|
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
func TestLongDescription(t *testing.T) {
|
|
|
|
// See https://github.com/MichaelMure/git-bug/issues/606
|
|
|
|
|
|
|
|
text := strings.Repeat("x", 65536)
|
|
|
|
|
|
|
|
repo := repository.CreateGoGitTestRepo(t, false)
|
|
|
|
|
|
|
|
backend := createTestRepoCacheNoEvents(t, repo)
|
|
|
|
|
|
|
|
i, err := backend.Identities().New("René Descartes", "rene@descartes.fr")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, _, err = backend.Bugs().NewRaw(i, time.Now().Unix(), text, text, nil, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:52:29 +03:00
|
|
|
func checkBugPresence(t *testing.T, cache *RepoCache, bug *BugCache, presence bool) {
|
2023-01-05 01:32:59 +03:00
|
|
|
t.Helper()
|
|
|
|
|
2020-07-26 10:52:29 +03:00
|
|
|
id := bug.Id()
|
2022-12-21 23:54:36 +03:00
|
|
|
require.Equal(t, presence, cache.bugs.lru.Contains(id))
|
|
|
|
b, ok := cache.bugs.cached[id]
|
2020-07-26 10:52:29 +03:00
|
|
|
require.Equal(t, presence, ok)
|
2020-08-25 05:43:42 +03:00
|
|
|
if ok {
|
|
|
|
require.Equal(t, bug, b)
|
|
|
|
}
|
2020-07-26 10:52:29 +03:00
|
|
|
}
|
2021-03-29 11:08:57 +03:00
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
func createTestRepoCacheNoEvents(t *testing.T, repo repository.TestedRepo) *RepoCache {
|
|
|
|
t.Helper()
|
2021-03-29 11:08:57 +03:00
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
cache, err := NewRepoCacheNoEvents(repo)
|
|
|
|
require.NoError(t, err)
|
2021-03-29 11:08:57 +03:00
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
t.Cleanup(func() {
|
|
|
|
require.NoError(t, cache.Close())
|
|
|
|
})
|
2021-03-29 11:08:57 +03:00
|
|
|
|
2023-01-05 01:32:59 +03:00
|
|
|
return cache
|
|
|
|
}
|