aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
commit7bec0b1f134d213e7505fc2ac03ffea26f2193cc (patch)
treee263cccd84406843eacbc6bd184acdacb25a49d1 /tests
parentb478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (diff)
downloadgit-bug-7bec0b1f134d213e7505fc2ac03ffea26f2193cc.tar.gz
bug: add a data validation process to avoid merging incorrect operations
Diffstat (limited to 'tests')
-rw-r--r--tests/bug_test.go26
-rw-r--r--tests/operation_iterator_test.go2
2 files changed, 17 insertions, 11 deletions
diff --git a/tests/bug_test.go b/tests/bug_test.go
index fdda31b1..02336974 100644
--- a/tests/bug_test.go
+++ b/tests/bug_test.go
@@ -2,10 +2,14 @@ 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)
@@ -20,33 +24,35 @@ func TestBugId(t *testing.T) {
}
func TestBugValidity(t *testing.T) {
+ mockRepo := repository.NewMockRepoForTest()
+
bug1 := bug.NewBug()
- if bug1.IsValid() {
+ if bug1.Validate() == nil {
t.Fatal("Empty bug should be invalid")
}
bug1.Append(createOp)
- if !bug1.IsValid() {
+ if bug1.Validate() != nil {
t.Fatal("Bug with just a CreateOp should be valid")
}
- bug1.Append(createOp)
-
- if bug1.IsValid() {
- t.Fatal("Bug with multiple CreateOp should be invalid")
- }
-
err := bug1.Commit(mockRepo)
-
if err != nil {
t.Fatal(err)
}
- if bug1.IsValid() {
+ 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) {
diff --git a/tests/operation_iterator_test.go b/tests/operation_iterator_test.go
index f1840091..790c8a62 100644
--- a/tests/operation_iterator_test.go
+++ b/tests/operation_iterator_test.go
@@ -18,10 +18,10 @@ var (
addCommentOp = operations.NewAddCommentOp(rene, "message2", nil)
setStatusOp = operations.NewSetStatusOp(rene, bug.ClosedStatus)
labelChangeOp = operations.NewLabelChangeOperation(rene, []bug.Label{"added"}, []bug.Label{"removed"})
- mockRepo = repository.NewMockRepoForTest()
)
func TestOpIterator(t *testing.T) {
+ mockRepo := repository.NewMockRepoForTest()
bug1 := bug.NewBug()