aboutsummaryrefslogtreecommitdiffstats
path: root/cache
diff options
context:
space:
mode:
authorvince <vincetiu8@gmail.com>2020-07-26 16:14:11 +0800
committerMichael Muré <batolettre@gmail.com>2020-07-28 14:30:07 +0200
commit18ddc775905bdeabf2be4afb6fe62d2013b06dec (patch)
treefec60394989a1dd318c819ddb6e3850fcc873da1 /cache
parent6e315ea131553d42768e678d5f86445dd3c54aa4 (diff)
downloadgit-bug-18ddc775905bdeabf2be4afb6fe62d2013b06dec.tar.gz
Fix bug tests
Diffstat (limited to 'cache')
-rw-r--r--cache/repo_cache_test.go53
1 files changed, 48 insertions, 5 deletions
diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go
index e5f8a037..e5603fca 100644
--- a/cache/repo_cache_test.go
+++ b/cache/repo_cache_test.go
@@ -1,8 +1,11 @@
package cache
import (
+ "fmt"
"testing"
+ "time"
+ "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/MichaelMure/git-bug/query"
@@ -101,11 +104,6 @@ func TestCache(t *testing.T) {
require.NoError(t, err)
_, err = cache.ResolveBugPrefix(bug1.Id().String()[:10])
require.NoError(t, err)
-
- // Possible to delete a bug
- err = cache.RemoveBug(bug1.Id().Human(), "")
- require.NoError(t, err)
- require.Equal(t, len(cache.AllBugsIds()), 1)
}
func TestPushPull(t *testing.T) {
@@ -162,3 +160,48 @@ func TestPushPull(t *testing.T) {
require.Len(t, cacheA.AllBugsIds(), 2)
}
+
+func TestRemove(t *testing.T) {
+ repo := repository.CreateTestRepo(false)
+ remoteA := repository.CreateTestRepo(true)
+ remoteB := repository.CreateTestRepo(true)
+ defer repository.CleanupTestRepos(repo, remoteA, remoteB)
+
+ err := repo.AddRemote("remoteA", "file://"+remoteA.GetPath())
+ require.NoError(t, err)
+
+ err = repo.AddRemote("remoteB", "file://"+remoteB.GetPath())
+ require.NoError(t, err)
+
+ repoCache, err := NewRepoCache(repo)
+ require.NoError(t, err)
+
+ // generate a bunch of bugs
+ rene, err := repoCache.NewIdentity("René Descartes", "rene@descartes.fr")
+ require.NoError(t, err)
+
+ for i := 0; i < 100; i++ {
+ _, _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", fmt.Sprintf("message%v", i), nil, nil)
+ require.NoError(t, err)
+ }
+
+ // and one more for testing
+ b1, _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil)
+ 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)
+
+ err = repoCache.RemoveBug(b1.Id().String())
+ require.NoError(t, err)
+ assert.Equal(t, 100, len(repoCache.bugs))
+}