1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package operations
import (
"testing"
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/util/git"
)
func TestValidate(t *testing.T) {
rene := bug.Person{
Name: "René Descartes",
Email: "rene@descartes.fr",
}
good := []bug.Operation{
NewCreateOp(rene, "title", "message", nil),
NewSetTitleOp(rene, "title2", "title1"),
NewAddCommentOp(rene, "message2", nil),
NewSetStatusOp(rene, bug.ClosedStatus),
NewLabelChangeOperation(rene, []bug.Label{"added"}, []bug.Label{"removed"}),
}
for _, op := range good {
if err := op.Validate(); err != nil {
t.Fatal(err)
}
}
bad := []bug.Operation{
// opbase
NewSetStatusOp(bug.Person{Name: "", Email: "rene@descartes.fr"}, bug.ClosedStatus),
NewSetStatusOp(bug.Person{Name: "René Descartes\u001b", Email: "rene@descartes.fr"}, bug.ClosedStatus),
NewSetStatusOp(bug.Person{Name: "René Descartes", Email: "rene@descartes.fr\u001b"}, bug.ClosedStatus),
NewSetStatusOp(bug.Person{Name: "René \nDescartes", Email: "rene@descartes.fr"}, bug.ClosedStatus),
NewSetStatusOp(bug.Person{Name: "René Descartes", Email: "rene@\ndescartes.fr"}, bug.ClosedStatus),
CreateOperation{OpBase: bug.OpBase{
Author: rene,
UnixTime: 0,
OperationType: bug.CreateOp,
},
Title: "title",
Message: "message",
},
NewCreateOp(rene, "multi\nline", "message", nil),
NewCreateOp(rene, "title", "message", []git.Hash{git.Hash("invalid")}),
NewCreateOp(rene, "title\u001b", "message", nil),
NewCreateOp(rene, "title", "message\u001b", nil),
NewSetTitleOp(rene, "multi\nline", "title1"),
NewSetTitleOp(rene, "title", "multi\nline"),
NewSetTitleOp(rene, "title\u001b", "title2"),
NewSetTitleOp(rene, "title", "title2\u001b"),
NewAddCommentOp(rene, "", nil),
NewAddCommentOp(rene, "message\u001b", nil),
NewAddCommentOp(rene, "message", []git.Hash{git.Hash("invalid")}),
NewSetStatusOp(rene, 1000),
NewSetStatusOp(rene, 0),
NewLabelChangeOperation(rene, []bug.Label{}, []bug.Label{}),
NewLabelChangeOperation(rene, []bug.Label{"multi\nline"}, []bug.Label{}),
}
for i, op := range bad {
if err := op.Validate(); err == nil {
t.Fatal("validation should have failed", i, op)
}
}
}
|