aboutsummaryrefslogtreecommitdiffstats
path: root/cache/repo_cache_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cache/repo_cache_test.go')
-rw-r--r--cache/repo_cache_test.go101
1 files changed, 101 insertions, 0 deletions
diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go
new file mode 100644
index 00000000..c90ad28e
--- /dev/null
+++ b/cache/repo_cache_test.go
@@ -0,0 +1,101 @@
+package cache
+
+import (
+ "testing"
+
+ "github.com/MichaelMure/git-bug/util/test"
+ "github.com/stretchr/testify/require"
+)
+
+func TestCache(t *testing.T) {
+ repo := test.CreateRepo(false)
+
+ cache, err := NewRepoCache(repo)
+ require.NoError(t, err)
+
+ // Create, set and get user identity
+ iden1, err := cache.NewIdentity("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())
+
+ // it's possible to create two identical identities
+ iden2, err := cache.NewIdentity("René Descartes", "rene@descartes.fr")
+ require.NoError(t, err)
+
+ // Two identical identities yield a different id
+ require.NotEqual(t, iden1.Id(), iden2.Id())
+
+ // There is now two identities in the cache
+ require.Len(t, cache.AllIdentityIds(), 2)
+ require.Len(t, cache.identitiesExcerpts, 2)
+ require.Len(t, cache.identities, 2)
+
+ // Create a bug
+ bug1, err := cache.NewBug("title", "message")
+ require.NoError(t, err)
+
+ // It's possible to create two identical bugs
+ bug2, err := cache.NewBug("title", "message")
+ require.NoError(t, err)
+
+ // two identical bugs yield a different id
+ require.NotEqual(t, bug1.Id(), bug2.Id())
+
+ // There is now two bugs in the cache
+ require.Len(t, cache.AllBugsIds(), 2)
+ require.Len(t, cache.bugExcerpts, 2)
+ require.Len(t, cache.bugs, 2)
+
+ // Resolving
+ _, err = cache.ResolveIdentity(iden1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveIdentityExcerpt(iden1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveIdentityPrefix(iden1.Id()[:10])
+ require.NoError(t, err)
+
+ _, err = cache.ResolveBug(bug1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveBugExcerpt(bug1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveBugPrefix(bug1.Id()[:10])
+ require.NoError(t, err)
+
+ // Querying
+ query, err := ParseQuery("status:open author:descartes sort:edit-asc")
+ require.NoError(t, err)
+ require.Len(t, cache.QueryBugs(query), 2)
+
+ // Close
+ require.NoError(t, cache.Close())
+ require.Empty(t, cache.bugs)
+ require.Empty(t, cache.bugExcerpts)
+ require.Empty(t, cache.identities)
+ require.Empty(t, cache.identitiesExcerpts)
+
+ // Reload, only excerpt are loaded
+ require.NoError(t, cache.load())
+ require.Empty(t, cache.bugs)
+ require.Empty(t, cache.identities)
+ require.Len(t, cache.bugExcerpts, 2)
+ require.Len(t, cache.identitiesExcerpts, 2)
+
+ // Resolving load from the disk
+ _, err = cache.ResolveIdentity(iden1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveIdentityExcerpt(iden1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveIdentityPrefix(iden1.Id()[:10])
+ require.NoError(t, err)
+
+ _, err = cache.ResolveBug(bug1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveBugExcerpt(bug1.Id())
+ require.NoError(t, err)
+ _, err = cache.ResolveBugPrefix(bug1.Id()[:10])
+ require.NoError(t, err)
+}