aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-13 17:07:24 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-13 17:07:24 +0200
commit289f8d53ee960d35c1f0c42e8753ad536737b875 (patch)
treeca1f0af1e041ff5779d39a79c486c331a88c0334 /tests
parentdeff9e0a41eca43f832314219241c9a63cf8007e (diff)
downloadgit-bug-289f8d53ee960d35c1f0c42e8753ad536737b875.tar.gz
little bit more tests
Diffstat (limited to 'tests')
-rw-r--r--tests/bug_test.go46
-rw-r--r--tests/operation_iterator_test.go51
2 files changed, 97 insertions, 0 deletions
diff --git a/tests/bug_test.go b/tests/bug_test.go
new file mode 100644
index 00000000..dfb3ac09
--- /dev/null
+++ b/tests/bug_test.go
@@ -0,0 +1,46 @@
+package tests
+
+import (
+ "github.com/MichaelMure/git-bug/bug"
+ "testing"
+)
+
+func TestBugId(t *testing.T) {
+ bug1, err := bug.NewBug()
+ if err != nil {
+ t.Error(err)
+ }
+
+ if len(bug1.HumanId()) == 0 {
+ t.Fatal("Bug doesn't have a human readable identifier")
+ }
+}
+
+func TestBugValidity(t *testing.T) {
+ 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/tests/operation_iterator_test.go b/tests/operation_iterator_test.go
new file mode 100644
index 00000000..e41fff99
--- /dev/null
+++ b/tests/operation_iterator_test.go
@@ -0,0 +1,51 @@
+package tests
+
+import (
+ "github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/bug/operations"
+ "testing"
+)
+
+var (
+ rene = bug.Person{
+ Name: "René Descartes",
+ Email: "rene@descartes.fr",
+ }
+
+ createOp = operations.NewCreateOp(rene, "title", "message")
+ setTitleOp = operations.NewSetTitleOp("title2")
+)
+
+func TestOpIterator(t *testing.T) {
+
+ 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)
+ }
+}