aboutsummaryrefslogtreecommitdiffstats
path: root/bug/bug_actions_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'bug/bug_actions_test.go')
-rw-r--r--bug/bug_actions_test.go343
1 files changed, 148 insertions, 195 deletions
diff --git a/bug/bug_actions_test.go b/bug/bug_actions_test.go
index a60e5c68..345b5e9a 100644
--- a/bug/bug_actions_test.go
+++ b/bug/bug_actions_test.go
@@ -1,93 +1,31 @@
package bug
import (
- "github.com/MichaelMure/git-bug/repository"
- "github.com/stretchr/testify/assert"
-
- "io/ioutil"
- "log"
- "os"
"testing"
-)
-
-func createRepo(bare bool) *repository.GitRepo {
- dir, err := ioutil.TempDir("", "")
- if err != nil {
- log.Fatal(err)
- }
-
- // fmt.Println("Creating repo:", dir)
-
- var creator func(string) (*repository.GitRepo, error)
-
- if bare {
- creator = repository.InitBareGitRepo
- } else {
- creator = repository.InitGitRepo
- }
-
- repo, err := creator(dir)
- if err != nil {
- log.Fatal(err)
- }
-
- if err := repo.StoreConfig("user.name", "testuser"); err != nil {
- log.Fatal("failed to set user.name for test repository: ", err)
- }
- if err := repo.StoreConfig("user.email", "testuser@example.com"); err != nil {
- log.Fatal("failed to set user.email for test repository: ", err)
- }
-
- return repo
-}
-
-func cleanupRepo(repo repository.Repo) error {
- path := repo.GetPath()
- // fmt.Println("Cleaning repo:", path)
- return os.RemoveAll(path)
-}
-
-func setupRepos(t testing.TB) (repoA, repoB, remote *repository.GitRepo) {
- repoA = createRepo(false)
- repoB = createRepo(false)
- remote = createRepo(true)
+ "time"
- remoteAddr := "file://" + remote.GetPath()
-
- err := repoA.AddRemote("origin", remoteAddr)
- if err != nil {
- t.Fatal(err)
- }
-
- err = repoB.AddRemote("origin", remoteAddr)
- if err != nil {
- t.Fatal(err)
- }
-
- return repoA, repoB, remote
-}
-
-func cleanupRepos(repoA, repoB, remote *repository.GitRepo) {
- cleanupRepo(repoA)
- cleanupRepo(repoB)
- cleanupRepo(remote)
-}
+ "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/test"
+ "github.com/stretchr/testify/require"
+)
func TestPushPull(t *testing.T) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
+ repoA, repoB, remote := test.SetupReposAndRemote(t)
+ defer test.CleanupRepos(repoA, repoB, remote)
- bug1, _, err := Create(rene, unix, "bug1", "message")
- assert.Nil(t, err)
+ reneA := identity.NewIdentity("René Descartes", "rene@descartes.fr")
+
+ bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
+ require.NoError(t, err)
// A --> remote --> B
_, err = Push(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
err = Pull(repoB, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bugs := allBugs(t, ReadAllLocalBugs(repoB))
@@ -96,16 +34,19 @@ func TestPushPull(t *testing.T) {
}
// B --> remote --> A
- bug2, _, err := Create(rene, unix, "bug2", "message")
- assert.Nil(t, err)
+ reneB, err := identity.ReadLocal(repoA, reneA.Id())
+ require.NoError(t, err)
+
+ bug2, _, err := Create(reneB, time.Now().Unix(), "bug2", "message")
+ require.NoError(t, err)
err = bug2.Commit(repoB)
- assert.Nil(t, err)
+ require.NoError(t, err)
_, err = Push(repoB, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
err = Pull(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bugs = allBugs(t, ReadAllLocalBugs(repoA))
@@ -136,41 +77,46 @@ func BenchmarkRebaseTheirs(b *testing.B) {
}
func _RebaseTheirs(t testing.TB) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
+ repoA, repoB, remote := test.SetupReposAndRemote(t)
+ defer test.CleanupRepos(repoA, repoB, remote)
+
+ reneA := identity.NewIdentity("René Descartes", "rene@descartes.fr")
- bug1, _, err := Create(rene, unix, "bug1", "message")
- assert.Nil(t, err)
+ bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
+ require.NoError(t, err)
// A --> remote
_, err = Push(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> B
err = Pull(repoB, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bug2, err := ReadLocalBug(repoB, bug1.Id())
- assert.Nil(t, err)
-
- _, err = AddComment(bug2, rene, unix, "message2")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message3")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message4")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ reneB, err := identity.ReadLocal(repoA, reneA.Id())
+ require.NoError(t, err)
+
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message2")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message3")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message4")
+ require.NoError(t, err)
err = bug2.Commit(repoB)
- assert.Nil(t, err)
+ require.NoError(t, err)
// B --> remote
_, err = Push(repoB, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> A
err = Pull(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bugs := allBugs(t, ReadAllLocalBugs(repoB))
@@ -179,7 +125,7 @@ func _RebaseTheirs(t testing.TB) {
}
bug3, err := ReadLocalBug(repoA, bug1.Id())
- assert.Nil(t, err)
+ require.NoError(t, err)
if nbOps(bug3) != 4 {
t.Fatal("Unexpected number of operations")
@@ -197,52 +143,54 @@ func BenchmarkRebaseOurs(b *testing.B) {
}
func _RebaseOurs(t testing.TB) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
+ repoA, repoB, remote := test.SetupReposAndRemote(t)
+ defer test.CleanupRepos(repoA, repoB, remote)
- bug1, _, err := Create(rene, unix, "bug1", "message")
- assert.Nil(t, err)
+ reneA := identity.NewIdentity("René Descartes", "rene@descartes.fr")
+
+ bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
+ require.NoError(t, err)
// A --> remote
_, err = Push(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> B
err = Pull(repoB, "origin")
- assert.Nil(t, err)
-
- _, err = AddComment(bug1, rene, unix, "message2")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message3")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message4")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message2")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message3")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message4")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
-
- _, err = AddComment(bug1, rene, unix, "message5")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message6")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message7")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message5")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message6")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message7")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
-
- _, err = AddComment(bug1, rene, unix, "message8")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message9")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message10")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message8")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message9")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message10")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> A
err = Pull(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bugs := allBugs(t, ReadAllLocalBugs(repoA))
@@ -251,7 +199,7 @@ func _RebaseOurs(t testing.TB) {
}
bug2, err := ReadLocalBug(repoA, bug1.Id())
- assert.Nil(t, err)
+ require.NoError(t, err)
if nbOps(bug2) != 10 {
t.Fatal("Unexpected number of operations")
@@ -278,86 +226,91 @@ func BenchmarkRebaseConflict(b *testing.B) {
}
func _RebaseConflict(t testing.TB) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
+ repoA, repoB, remote := test.SetupReposAndRemote(t)
+ defer test.CleanupRepos(repoA, repoB, remote)
+
+ reneA := identity.NewIdentity("René Descartes", "rene@descartes.fr")
- bug1, _, err := Create(rene, unix, "bug1", "message")
- assert.Nil(t, err)
+ bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
+ require.NoError(t, err)
// A --> remote
_, err = Push(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> B
err = Pull(repoB, "origin")
- assert.Nil(t, err)
-
- _, err = AddComment(bug1, rene, unix, "message2")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message3")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message4")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message2")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message3")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message4")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
-
- _, err = AddComment(bug1, rene, unix, "message5")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message6")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message7")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message5")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message6")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message7")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
-
- _, err = AddComment(bug1, rene, unix, "message8")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message9")
- assert.Nil(t, err)
- _, err = AddComment(bug1, rene, unix, "message10")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message8")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message9")
+ require.NoError(t, err)
+ _, err = AddComment(bug1, reneA, time.Now().Unix(), "message10")
+ require.NoError(t, err)
err = bug1.Commit(repoA)
- assert.Nil(t, err)
+ require.NoError(t, err)
bug2, err := ReadLocalBug(repoB, bug1.Id())
- assert.Nil(t, err)
-
- _, err = AddComment(bug2, rene, unix, "message11")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message12")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message13")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ reneB, err := identity.ReadLocal(repoA, reneA.Id())
+ require.NoError(t, err)
+
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message11")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message12")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message13")
+ require.NoError(t, err)
err = bug2.Commit(repoB)
- assert.Nil(t, err)
-
- _, err = AddComment(bug2, rene, unix, "message14")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message15")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message16")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message14")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message15")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message16")
+ require.NoError(t, err)
err = bug2.Commit(repoB)
- assert.Nil(t, err)
-
- _, err = AddComment(bug2, rene, unix, "message17")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message18")
- assert.Nil(t, err)
- _, err = AddComment(bug2, rene, unix, "message19")
- assert.Nil(t, err)
+ require.NoError(t, err)
+
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message17")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message18")
+ require.NoError(t, err)
+ _, err = AddComment(bug2, reneB, time.Now().Unix(), "message19")
+ require.NoError(t, err)
err = bug2.Commit(repoB)
- assert.Nil(t, err)
+ require.NoError(t, err)
// A --> remote
_, err = Push(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> B
err = Pull(repoB, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bugs := allBugs(t, ReadAllLocalBugs(repoB))
@@ -366,7 +319,7 @@ func _RebaseConflict(t testing.TB) {
}
bug3, err := ReadLocalBug(repoB, bug1.Id())
- assert.Nil(t, err)
+ require.NoError(t, err)
if nbOps(bug3) != 19 {
t.Fatal("Unexpected number of operations")
@@ -374,11 +327,11 @@ func _RebaseConflict(t testing.TB) {
// B --> remote
_, err = Push(repoB, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
// remote --> A
err = Pull(repoA, "origin")
- assert.Nil(t, err)
+ require.NoError(t, err)
bugs = allBugs(t, ReadAllLocalBugs(repoA))
@@ -387,7 +340,7 @@ func _RebaseConflict(t testing.TB) {
}
bug4, err := ReadLocalBug(repoA, bug1.Id())
- assert.Nil(t, err)
+ require.NoError(t, err)
if nbOps(bug4) != 19 {
t.Fatal("Unexpected number of operations")