aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation_test.go
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 /bug/operation_test.go
parent8af6f7d98f2fd98f85d6a17bcda49983c272cf48 (diff)
downloadgit-bug-1bf268cebc84a9de1e538cbb54bcc0f434022192.tar.gz
merge package operations into bug, they are tightly coupled anyway
Diffstat (limited to 'bug/operation_test.go')
-rw-r--r--bug/operation_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/bug/operation_test.go b/bug/operation_test.go
new file mode 100644
index 00000000..8561adf3
--- /dev/null
+++ b/bug/operation_test.go
@@ -0,0 +1,70 @@
+package bug
+
+import (
+ "testing"
+ "time"
+
+ "github.com/MichaelMure/git-bug/util/git"
+)
+
+func TestValidate(t *testing.T) {
+ rene := Person{
+ Name: "René Descartes",
+ Email: "rene@descartes.fr",
+ }
+
+ unix := time.Now().Unix()
+
+ good := []Operation{
+ NewCreateOp(rene, unix, "title", "message", nil),
+ NewSetTitleOp(rene, unix, "title2", "title1"),
+ NewAddCommentOp(rene, unix, "message2", nil),
+ NewSetStatusOp(rene, unix, ClosedStatus),
+ NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"}),
+ }
+
+ for _, op := range good {
+ if err := op.Validate(); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ bad := []Operation{
+ // opbase
+ NewSetStatusOp(Person{Name: "", Email: "rene@descartes.fr"}, unix, ClosedStatus),
+ NewSetStatusOp(Person{Name: "René Descartes\u001b", Email: "rene@descartes.fr"}, unix, ClosedStatus),
+ NewSetStatusOp(Person{Name: "René Descartes", Email: "rene@descartes.fr\u001b"}, unix, ClosedStatus),
+ NewSetStatusOp(Person{Name: "René \nDescartes", Email: "rene@descartes.fr"}, unix, ClosedStatus),
+ NewSetStatusOp(Person{Name: "René Descartes", Email: "rene@\ndescartes.fr"}, unix, ClosedStatus),
+ CreateOperation{OpBase: &OpBase{
+ Author: rene,
+ UnixTime: 0,
+ OperationType: CreateOp,
+ },
+ Title: "title",
+ Message: "message",
+ },
+
+ NewCreateOp(rene, unix, "multi\nline", "message", nil),
+ NewCreateOp(rene, unix, "title", "message", []git.Hash{git.Hash("invalid")}),
+ NewCreateOp(rene, unix, "title\u001b", "message", nil),
+ NewCreateOp(rene, unix, "title", "message\u001b", nil),
+ NewSetTitleOp(rene, unix, "multi\nline", "title1"),
+ NewSetTitleOp(rene, unix, "title", "multi\nline"),
+ NewSetTitleOp(rene, unix, "title\u001b", "title2"),
+ NewSetTitleOp(rene, unix, "title", "title2\u001b"),
+ NewAddCommentOp(rene, unix, "", nil),
+ NewAddCommentOp(rene, unix, "message\u001b", nil),
+ NewAddCommentOp(rene, unix, "message", []git.Hash{git.Hash("invalid")}),
+ NewSetStatusOp(rene, unix, 1000),
+ NewSetStatusOp(rene, unix, 0),
+ NewLabelChangeOperation(rene, unix, []Label{}, []Label{}),
+ NewLabelChangeOperation(rene, unix, []Label{"multi\nline"}, []Label{}),
+ }
+
+ for i, op := range bad {
+ if err := op.Validate(); err == nil {
+ t.Fatal("validation should have failed", i, op)
+ }
+ }
+}