MCPcopy Index your code
hub / github.com/git-bug/git-bug / TestCache

Function TestCache

cache/repo_cache_test.go:19–183  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestCache(t *testing.T) {
20 f := test.NewFlaky(t, &test.FlakyOptions{
21 MaxAttempts: 5,
22 })
23
24 f.Run(func(t testing.TB) {
25 repo := repository.CreateGoGitTestRepo(t, false)
26 indexCount := func(t testing.TB, name string) uint64 {
27 t.Helper()
28
29 idx, err := repo.GetIndex(name)
30 require.NoError(t, err)
31 count, err := idx.DocCount()
32 require.NoError(t, err)
33
34 return count
35 }
36
37 cache, err := NewRepoCacheNoEvents(repo)
38 require.NoError(t, err)
39
40 // Create, set and get user identity
41 iden1, err := cache.Identities().New("René Descartes", "rene@descartes.fr")
42 require.NoError(t, err)
43 err = cache.SetUserIdentity(iden1)
44 require.NoError(t, err)
45 userIden, err := cache.GetUserIdentity()
46 require.NoError(t, err)
47 require.Equal(t, iden1.Id(), userIden.Id())
48
49 // it's possible to create two identical identities
50 iden2, err := cache.Identities().New("René Descartes", "rene@descartes.fr")
51 require.NoError(t, err)
52
53 // Two identical identities yield a different id
54 require.NotEqual(t, iden1.Id(), iden2.Id())
55
56 // There is now two identities in the cache
57 require.Len(t, cache.Identities().AllIds(), 2)
58 require.Len(t, cache.identities.excerpts, 2)
59 require.Len(t, cache.identities.cached, 2)
60 require.Equal(t, uint64(2), indexCount(t, identity.Namespace))
61 require.Equal(t, uint64(0), indexCount(t, bug.Namespace))
62
63 // Create a bug
64 bug1, _, err := cache.Bugs().New("title", "message")
65 require.NoError(t, err)
66
67 // It's possible to create two identical bugs
68 bug2, _, err := cache.Bugs().New("title", "marker")
69 require.NoError(t, err)
70
71 // two identical bugs yield a different id
72 require.NotEqual(t, bug1.Id(), bug2.Id())
73
74 // There is now two bugs in the cache
75 require.Len(t, cache.Bugs().AllIds(), 2)
76 require.Len(t, cache.bugs.excerpts, 2)

Callers

nothing calls this directly

Calls 15

NewFlakyFunction · 0.92
CreateGoGitTestRepoFunction · 0.92
ParseFunction · 0.92
NewRepoCacheNoEventsFunction · 0.85
RunMethod · 0.80
HelperMethod · 0.80
IdentitiesMethod · 0.80
SetUserIdentityMethod · 0.80
GetUserIdentityMethod · 0.80
AllIdsMethod · 0.80
BugsMethod · 0.80
ResolveExcerptMethod · 0.80

Tested by

no test coverage detected