aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-28 20:39:39 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-29 00:51:54 +0200
commit1bf268cebc84a9de1e538cbb54bcc0f434022192 (patch)
treedaeb92cd6b15d56a7a7102f95b73756e5b9597d0 /tests
parent8af6f7d98f2fd98f85d6a17bcda49983c272cf48 (diff)
downloadgit-bug-1bf268cebc84a9de1e538cbb54bcc0f434022192.tar.gz
merge package operations into bug, they are tightly coupled anyway
Diffstat (limited to 'tests')
-rw-r--r--tests/bug_actions_test.go365
-rw-r--r--tests/bug_test.go81
-rw-r--r--tests/operation_iterator_test.go61
-rw-r--r--tests/operation_pack_test.go54
-rw-r--r--tests/read_bugs_test.go26
5 files changed, 26 insertions, 561 deletions
diff --git a/tests/bug_actions_test.go b/tests/bug_actions_test.go
deleted file mode 100644
index 50333cd2..00000000
--- a/tests/bug_actions_test.go
+++ /dev/null
@@ -1,365 +0,0 @@
-package tests
-
-import (
- "io/ioutil"
- "log"
- "os"
- "testing"
-
- "github.com/MichaelMure/git-bug/bug"
- "github.com/MichaelMure/git-bug/operations"
- "github.com/MichaelMure/git-bug/repository"
-)
-
-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)
- }
-
- 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)
-
- 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)
-}
-
-func TestPushPull(t *testing.T) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
-
- bug1, err := operations.Create(rene, unix, "bug1", "message")
- checkErr(t, err)
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- // A --> remote --> B
- _, err = bug.Push(repoA, "origin")
- checkErr(t, err)
-
- err = bug.Pull(repoB, "origin")
- checkErr(t, err)
-
- bugs := allBugs(t, bug.ReadAllLocalBugs(repoB))
-
- if len(bugs) != 1 {
- t.Fatal("Unexpected number of bugs")
- }
-
- // B --> remote --> A
- bug2, err := operations.Create(rene, unix, "bug2", "message")
- checkErr(t, err)
- err = bug2.Commit(repoB)
- checkErr(t, err)
-
- _, err = bug.Push(repoB, "origin")
- checkErr(t, err)
-
- err = bug.Pull(repoA, "origin")
- checkErr(t, err)
-
- bugs = allBugs(t, bug.ReadAllLocalBugs(repoA))
-
- if len(bugs) != 2 {
- t.Fatal("Unexpected number of bugs")
- }
-}
-
-func checkErr(t testing.TB, err error) {
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func allBugs(t testing.TB, bugs <-chan bug.StreamedBug) []*bug.Bug {
- var result []*bug.Bug
- for streamed := range bugs {
- if streamed.Err != nil {
- t.Fatal(streamed.Err)
- }
- result = append(result, streamed.Bug)
- }
- return result
-}
-
-func TestRebaseTheirs(t *testing.T) {
- _RebaseTheirs(t)
-}
-
-func BenchmarkRebaseTheirs(b *testing.B) {
- for n := 0; n < b.N; n++ {
- _RebaseTheirs(b)
- }
-}
-
-func _RebaseTheirs(t testing.TB) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
-
- bug1, err := operations.Create(rene, unix, "bug1", "message")
- checkErr(t, err)
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- // A --> remote
- _, err = bug.Push(repoA, "origin")
- checkErr(t, err)
-
- // remote --> B
- err = bug.Pull(repoB, "origin")
- checkErr(t, err)
-
- bug2, err := bug.ReadLocalBug(repoB, bug1.Id())
- checkErr(t, err)
-
- operations.Comment(bug2, rene, unix, "message2")
- operations.Comment(bug2, rene, unix, "message3")
- operations.Comment(bug2, rene, unix, "message4")
- err = bug2.Commit(repoB)
- checkErr(t, err)
-
- // B --> remote
- _, err = bug.Push(repoB, "origin")
- checkErr(t, err)
-
- // remote --> A
- err = bug.Pull(repoA, "origin")
- checkErr(t, err)
-
- bugs := allBugs(t, bug.ReadAllLocalBugs(repoB))
-
- if len(bugs) != 1 {
- t.Fatal("Unexpected number of bugs")
- }
-
- bug3, err := bug.ReadLocalBug(repoA, bug1.Id())
- checkErr(t, err)
-
- if nbOps(bug3) != 4 {
- t.Fatal("Unexpected number of operations")
- }
-}
-
-func TestRebaseOurs(t *testing.T) {
- _RebaseOurs(t)
-}
-
-func BenchmarkRebaseOurs(b *testing.B) {
- for n := 0; n < b.N; n++ {
- _RebaseOurs(b)
- }
-}
-
-func _RebaseOurs(t testing.TB) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
-
- bug1, err := operations.Create(rene, unix, "bug1", "message")
- checkErr(t, err)
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- // A --> remote
- _, err = bug.Push(repoA, "origin")
- checkErr(t, err)
-
- // remote --> B
- err = bug.Pull(repoB, "origin")
- checkErr(t, err)
-
- operations.Comment(bug1, rene, unix, "message2")
- operations.Comment(bug1, rene, unix, "message3")
- operations.Comment(bug1, rene, unix, "message4")
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- operations.Comment(bug1, rene, unix, "message5")
- operations.Comment(bug1, rene, unix, "message6")
- operations.Comment(bug1, rene, unix, "message7")
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- operations.Comment(bug1, rene, unix, "message8")
- operations.Comment(bug1, rene, unix, "message9")
- operations.Comment(bug1, rene, unix, "message10")
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- // remote --> A
- err = bug.Pull(repoA, "origin")
- checkErr(t, err)
-
- bugs := allBugs(t, bug.ReadAllLocalBugs(repoA))
-
- if len(bugs) != 1 {
- t.Fatal("Unexpected number of bugs")
- }
-
- bug2, err := bug.ReadLocalBug(repoA, bug1.Id())
- checkErr(t, err)
-
- if nbOps(bug2) != 10 {
- t.Fatal("Unexpected number of operations")
- }
-}
-
-func nbOps(b *bug.Bug) int {
- it := bug.NewOperationIterator(b)
- counter := 0
- for it.Next() {
- counter++
- }
- return counter
-}
-
-func TestRebaseConflict(t *testing.T) {
- _RebaseConflict(t)
-}
-
-func BenchmarkRebaseConflict(b *testing.B) {
- for n := 0; n < b.N; n++ {
- _RebaseConflict(b)
- }
-}
-
-func _RebaseConflict(t testing.TB) {
- repoA, repoB, remote := setupRepos(t)
- defer cleanupRepos(repoA, repoB, remote)
-
- bug1, err := operations.Create(rene, unix, "bug1", "message")
- checkErr(t, err)
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- // A --> remote
- _, err = bug.Push(repoA, "origin")
- checkErr(t, err)
-
- // remote --> B
- err = bug.Pull(repoB, "origin")
- checkErr(t, err)
-
- operations.Comment(bug1, rene, unix, "message2")
- operations.Comment(bug1, rene, unix, "message3")
- operations.Comment(bug1, rene, unix, "message4")
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- operations.Comment(bug1, rene, unix, "message5")
- operations.Comment(bug1, rene, unix, "message6")
- operations.Comment(bug1, rene, unix, "message7")
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- operations.Comment(bug1, rene, unix, "message8")
- operations.Comment(bug1, rene, unix, "message9")
- operations.Comment(bug1, rene, unix, "message10")
- err = bug1.Commit(repoA)
- checkErr(t, err)
-
- bug2, err := bug.ReadLocalBug(repoB, bug1.Id())
- checkErr(t, err)
-
- operations.Comment(bug2, rene, unix, "message11")
- operations.Comment(bug2, rene, unix, "message12")
- operations.Comment(bug2, rene, unix, "message13")
- err = bug2.Commit(repoB)
- checkErr(t, err)
-
- operations.Comment(bug2, rene, unix, "message14")
- operations.Comment(bug2, rene, unix, "message15")
- operations.Comment(bug2, rene, unix, "message16")
- err = bug2.Commit(repoB)
- checkErr(t, err)
-
- operations.Comment(bug2, rene, unix, "message17")
- operations.Comment(bug2, rene, unix, "message18")
- operations.Comment(bug2, rene, unix, "message19")
- err = bug2.Commit(repoB)
- checkErr(t, err)
-
- // A --> remote
- _, err = bug.Push(repoA, "origin")
- checkErr(t, err)
-
- // remote --> B
- err = bug.Pull(repoB, "origin")
- checkErr(t, err)
-
- bugs := allBugs(t, bug.ReadAllLocalBugs(repoB))
-
- if len(bugs) != 1 {
- t.Fatal("Unexpected number of bugs")
- }
-
- bug3, err := bug.ReadLocalBug(repoB, bug1.Id())
- checkErr(t, err)
-
- if nbOps(bug3) != 19 {
- t.Fatal("Unexpected number of operations")
- }
-
- // B --> remote
- _, err = bug.Push(repoB, "origin")
- checkErr(t, err)
-
- // remote --> A
- err = bug.Pull(repoA, "origin")
- checkErr(t, err)
-
- bugs = allBugs(t, bug.ReadAllLocalBugs(repoA))
-
- if len(bugs) != 1 {
- t.Fatal("Unexpected number of bugs")
- }
-
- bug4, err := bug.ReadLocalBug(repoA, bug1.Id())
- checkErr(t, err)
-
- if nbOps(bug4) != 19 {
- t.Fatal("Unexpected number of operations")
- }
-}
diff --git a/tests/bug_test.go b/tests/bug_test.go
deleted file mode 100644
index 02336974..00000000
--- a/tests/bug_test.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package tests
-
-import (
- "github.com/MichaelMure/git-bug/bug"
- "github.com/MichaelMure/git-bug/repository"
-
- "testing"
-)
-
-func TestBugId(t *testing.T) {
- mockRepo := repository.NewMockRepoForTest()
-
- bug1 := bug.NewBug()
-
- bug1.Append(createOp)
-
- err := bug1.Commit(mockRepo)
-
- if err != nil {
- t.Fatal(err)
- }
-
- bug1.Id()
-}
-
-func TestBugValidity(t *testing.T) {
- mockRepo := repository.NewMockRepoForTest()
-
- bug1 := bug.NewBug()
-
- if bug1.Validate() == nil {
- t.Fatal("Empty bug should be invalid")
- }
-
- bug1.Append(createOp)
-
- if bug1.Validate() != nil {
- t.Fatal("Bug with just a CreateOp should be valid")
- }
-
- err := bug1.Commit(mockRepo)
- if err != nil {
- t.Fatal(err)
- }
-
- bug1.Append(createOp)
-
- if bug1.Validate() == nil {
- t.Fatal("Bug with multiple CreateOp should be invalid")
- }
-
- err = bug1.Commit(mockRepo)
- if err == nil {
- t.Fatal("Invalid bug should not commit")
- }
-}
-
-//func TestBugSerialisation(t *testing.T) {
-// bug1, err := bug.NewBug()
-// if err != nil {
-// t.Error(err)
-// }
-//
-// bug1.Append(createOp)
-// bug1.Append(setTitleOp)
-// bug1.Append(setTitleOp)
-// bug1.Append(addCommentOp)
-//
-// repo := repository.NewMockRepoForTest()
-//
-// bug1.Commit(repo)
-//
-// bug2, err := bug.ReadBug(repo, bug.BugsRefPattern+bug1.Id())
-// if err != nil {
-// t.Error(err)
-// }
-//
-// if !reflect.DeepEqual(bug1, bug2) {
-// t.Fatalf("%v different than %v", bug1, bug2)
-// }
-//}
diff --git a/tests/operation_iterator_test.go b/tests/operation_iterator_test.go
deleted file mode 100644
index 524a639c..00000000
--- a/tests/operation_iterator_test.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package tests
-
-import (
- "github.com/MichaelMure/git-bug/bug"
- "github.com/MichaelMure/git-bug/operations"
- "github.com/MichaelMure/git-bug/repository"
- "testing"
- "time"
-)
-
-var (
- rene = bug.Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
-
- unix = time.Now().Unix()
-
- createOp = operations.NewCreateOp(rene, unix, "title", "message", nil)
- setTitleOp = operations.NewSetTitleOp(rene, unix, "title2", "title1")
- addCommentOp = operations.NewAddCommentOp(rene, unix, "message2", nil)
- setStatusOp = operations.NewSetStatusOp(rene, unix, bug.ClosedStatus)
- labelChangeOp = operations.NewLabelChangeOperation(rene, unix, []bug.Label{"added"}, []bug.Label{"removed"})
-)
-
-func TestOpIterator(t *testing.T) {
- mockRepo := repository.NewMockRepoForTest()
-
- bug1 := bug.NewBug()
-
- // first pack
- bug1.Append(createOp)
- bug1.Append(setTitleOp)
- bug1.Append(addCommentOp)
- bug1.Append(setStatusOp)
- bug1.Append(labelChangeOp)
- bug1.Commit(mockRepo)
-
- // second pack
- bug1.Append(setTitleOp)
- bug1.Append(setTitleOp)
- bug1.Append(setTitleOp)
- bug1.Commit(mockRepo)
-
- // staging
- bug1.Append(setTitleOp)
- bug1.Append(setTitleOp)
- bug1.Append(setTitleOp)
-
- it := bug.NewOperationIterator(bug1)
-
- counter := 0
- for it.Next() {
- _ = it.Value()
- counter++
- }
-
- if counter != 11 {
- t.Fatalf("Wrong count of value iterated (%d instead of 8)", counter)
- }
-}
diff --git a/tests/operation_pack_test.go b/tests/operation_pack_test.go
deleted file mode 100644
index aab1f1c9..00000000
--- a/tests/operation_pack_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-package tests
-
-import (
- "encoding/json"
- "reflect"
- "testing"
-
- "github.com/MichaelMure/git-bug/bug"
- "github.com/MichaelMure/git-bug/operations"
- "github.com/MichaelMure/git-bug/util/git"
-)
-
-func TestOperationPackSerialize(t *testing.T) {
- opp := &bug.OperationPack{}
-
- opp.Append(createOp)
- opp.Append(setTitleOp)
- opp.Append(addCommentOp)
- opp.Append(setStatusOp)
- opp.Append(labelChangeOp)
-
- opMeta := operations.NewCreateOp(rene, unix, "title", "message", nil)
- opMeta.SetMetadata("key", "value")
- opp.Append(opMeta)
-
- if len(opMeta.Metadata) != 1 {
- t.Fatal()
- }
-
- opFile := operations.NewCreateOp(rene, unix, "title", "message", []git.Hash{
- "abcdef",
- "ghijkl",
- })
- opp.Append(opFile)
-
- if len(opFile.Files) != 2 {
- t.Fatal()
- }
-
- data, err := json.Marshal(opp)
- if err != nil {
- t.Fatal(err)
- }
-
- var opp2 *bug.OperationPack
- err = json.Unmarshal(data, &opp2)
- if err != nil {
- t.Fatal(err)
- }
-
- if !reflect.DeepEqual(opp, opp2) {
- t.Fatalf("%v and %v are different", opp, opp2)
- }
-}
diff --git a/tests/read_bugs_test.go b/tests/read_bugs_test.go
index c3c7d9ea..b28da49b 100644
--- a/tests/read_bugs_test.go
+++ b/tests/read_bugs_test.go
@@ -1,6 +1,8 @@
package tests
import (
+ "io/ioutil"
+ "log"
"testing"
"github.com/MichaelMure/git-bug/bug"
@@ -8,6 +10,30 @@ import (
"github.com/MichaelMure/git-bug/repository"
)
+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)
+ }
+
+ return repo
+}
+
func createFilledRepo(bugNumber int) repository.ClockedRepo {
repo := createRepo(false)