aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-30 11:10:03 +0200
committerGitHub <noreply@github.com>2018-09-30 11:10:03 +0200
commitd71bb7dd7632780cf5aad5fda84027fa03a9d0f0 (patch)
treedba6c3c0bab18f41e21cd36a9fe05d1d27a574d4 /bug/operation_test.go
parent8fdd6bf99c111c3756056e87ffd9209875ac5c1f (diff)
parentbad9cda969b49bf1bce6799056476ac4684892df (diff)
downloadgit-bug-d71bb7dd7632780cf5aad5fda84027fa03a9d0f0.tar.gz
Merge pull request #54 from MichaelMure/editablecomment
Core support for editable comments
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..098cf138
--- /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)
+ }
+ }
+}