aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 16:48:55 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 16:48:55 +0200
commitdeff9e0a41eca43f832314219241c9a63cf8007e (patch)
tree215e07e7a77972cee50268603eeb3777de583e8b /test
parent078545538e6e6bf7a050fe6602a42a61fb5203e9 (diff)
downloadgit-bug-deff9e0a41eca43f832314219241c9a63cf8007e.tar.gz
add basic tests for Bug and OperationIterator
Diffstat (limited to 'test')
-rw-r--r--test/bug_test.go44
-rw-r--r--test/operation_iterator_test.go48
2 files changed, 92 insertions, 0 deletions
diff --git a/test/bug_test.go b/test/bug_test.go
new file mode 100644
index 00000000..d7c3ddc5
--- /dev/null
+++ b/test/bug_test.go
@@ -0,0 +1,44 @@
+package test
+
+import (
+ "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/bug/operations"
+ "testing"
+)
+
+func TestBug(t *testing.T) {
+ var rene = bug.Person{
+ Name: "René Descartes",
+ Email: "rene@descartes.fr",
+ }
+
+ var createOp = operations.NewCreateOp(rene, "title", "message")
+
+ bug1, err := bug.NewBug()
+
+ if err != nil {
+ t.Error(err)
+ }
+
+ if bug1.IsValid() {
+ t.Fatal("Empty bug should be invalid")
+ }
+
+ bug1.Append(createOp)
+
+ if !bug1.IsValid() {
+ t.Fatal("Bug with just a CREATE should be valid")
+ }
+
+ bug1.Append(createOp)
+
+ if bug1.IsValid() {
+ t.Fatal("Bug with multiple CREATE should be invalid")
+ }
+
+ bug1.Commit()
+
+ if bug1.IsValid() {
+ t.Fatal("Bug with multiple CREATE should be invalid")
+ }
+}
diff --git a/test/operation_iterator_test.go b/test/operation_iterator_test.go
new file mode 100644
index 00000000..d8e78a1f
--- /dev/null
+++ b/test/operation_iterator_test.go
@@ -0,0 +1,48 @@
+package test
+
+import (
+ "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/bug/operations"
+ "testing"
+)
+
+func TestOpIterator(t *testing.T) {
+ var rene = bug.Person{
+ Name: "René Descartes",
+ Email: "rene@descartes.fr",
+ }
+
+ var createOp = operations.NewCreateOp(rene, "title", "message")
+ var setTitleOp = operations.NewSetTitleOp("title2")
+
+ bug1, err := bug.NewBug()
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ bug1.Append(createOp)
+ bug1.Append(setTitleOp)
+ bug1.Commit()
+
+ bug1.Append(setTitleOp)
+ bug1.Append(setTitleOp)
+ bug1.Append(setTitleOp)
+ bug1.Commit()
+
+ bug1.Append(setTitleOp)
+ bug1.Append(setTitleOp)
+ bug1.Append(setTitleOp)
+
+ it := bug.NewOperationIterator(bug1)
+
+ counter := 0
+ for it.Next() {
+ _ = it.Value()
+ counter++
+ }
+
+ if counter != 8 {
+ t.Fatalf("Wrong count of value iterated (%d instead of 8)", counter)
+ }
+}