aboutsummaryrefslogtreecommitdiffstats
path: root/bug/bug_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-03-01 23:17:57 +0100
committerGitHub <noreply@github.com>2019-03-01 23:17:57 +0100
commit7260ca05bc3588c0572887a7d8f1b897c7fc13da (patch)
tree66854358df3cb9de651f7688556ec5a4b8ab1868 /bug/bug_test.go
parent0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff)
parentb6bed784e5664819250aac20b2b9690879ee6ab1 (diff)
downloadgit-bug-7260ca05bc3588c0572887a7d8f1b897c7fc13da.tar.gz
Merge pull request #89 from MichaelMure/identity
WIP identity in git
Diffstat (limited to 'bug/bug_test.go')
-rw-r--r--bug/bug_test.go57
1 files changed, 37 insertions, 20 deletions
diff --git a/bug/bug_test.go b/bug/bug_test.go
index 0fd373d5..4c3952eb 100644
--- a/bug/bug_test.go
+++ b/bug/bug_test.go
@@ -1,11 +1,12 @@
package bug
import (
+ "testing"
+ "time"
+
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
- "github.com/go-test/deep"
"github.com/stretchr/testify/assert"
-
- "testing"
)
func TestBugId(t *testing.T) {
@@ -13,6 +14,9 @@ func TestBugId(t *testing.T) {
bug1 := NewBug()
+ rene := identity.NewIdentity("René Descartes", "rene@descartes.fr")
+ createOp := NewCreateOp(rene, time.Now().Unix(), "title", "message", nil)
+
bug1.Append(createOp)
err := bug1.Commit(mockRepo)
@@ -29,6 +33,9 @@ func TestBugValidity(t *testing.T) {
bug1 := NewBug()
+ rene := identity.NewIdentity("René Descartes", "rene@descartes.fr")
+ createOp := NewCreateOp(rene, time.Now().Unix(), "title", "message", nil)
+
if bug1.Validate() == nil {
t.Fatal("Empty bug should be invalid")
}
@@ -56,9 +63,14 @@ func TestBugValidity(t *testing.T) {
}
}
-func TestBugSerialisation(t *testing.T) {
+func TestBugCommitLoad(t *testing.T) {
bug1 := NewBug()
+ rene := identity.NewIdentity("René Descartes", "rene@descartes.fr")
+ createOp := NewCreateOp(rene, time.Now().Unix(), "title", "message", nil)
+ setTitleOp := NewSetTitleOp(rene, time.Now().Unix(), "title2", "title1")
+ addCommentOp := NewAddCommentOp(rene, time.Now().Unix(), "message2", nil)
+
bug1.Append(createOp)
bug1.Append(setTitleOp)
bug1.Append(setTitleOp)
@@ -70,25 +82,30 @@ func TestBugSerialisation(t *testing.T) {
assert.Nil(t, err)
bug2, err := ReadLocalBug(repo, bug1.Id())
- if err != nil {
- t.Error(err)
- }
+ assert.NoError(t, err)
+ equivalentBug(t, bug1, bug2)
- // ignore some fields
- bug2.packs[0].commitHash = bug1.packs[0].commitHash
- for i := range bug1.packs[0].Operations {
- bug2.packs[0].Operations[i].base().hash = bug1.packs[0].Operations[i].base().hash
- }
+ // add more op
- // check hashes
- for i := range bug1.packs[0].Operations {
- if !bug2.packs[0].Operations[i].base().hash.IsValid() {
- t.Fatal("invalid hash")
+ bug1.Append(setTitleOp)
+ bug1.Append(addCommentOp)
+
+ err = bug1.Commit(repo)
+ assert.Nil(t, err)
+
+ bug3, err := ReadLocalBug(repo, bug1.Id())
+ assert.NoError(t, err)
+ equivalentBug(t, bug1, bug3)
+}
+
+func equivalentBug(t *testing.T, expected, actual *Bug) {
+ assert.Equal(t, len(expected.packs), len(actual.packs))
+
+ for i := range expected.packs {
+ for j := range expected.packs[i].Operations {
+ actual.packs[i].Operations[j].base().hash = expected.packs[i].Operations[j].base().hash
}
}
- deep.CompareUnexportedFields = true
- if diff := deep.Equal(bug1, bug2); diff != nil {
- t.Fatal(diff)
- }
+ assert.Equal(t, expected, actual)
}