MCPcopy Index your code
hub / github.com/git-bug/git-bug / TestValidate

Function TestValidate

entities/bug/operation_test.go:17–77  ·  view source on GitHub ↗

TODO: move to entity/dag?

(t *testing.T)

Source from the content-addressed store, hash-verified

15// TODO: move to entity/dag?
16
17func TestValidate(t *testing.T) {
18 repo := repository.NewMockRepoClock()
19
20 makeIdentity := func(t *testing.T, name, email string) *identity.Identity {
21 i, err := identity.NewIdentity(repo, name, email)
22 require.NoError(t, err)
23 return i
24 }
25
26 rene := makeIdentity(t, "René Descartes", "rene@descartes.fr")
27
28 unix := time.Now().Unix()
29
30 good := []Operation{
31 NewCreateOp(rene, unix, "title", "message", nil),
32 NewSetTitleOp(rene, unix, "title2", "title1"),
33 NewAddCommentOp(rene, unix, "message2", nil),
34 NewSetStatusOp(rene, unix, common.ClosedStatus),
35 NewLabelChangeOperation(rene, unix, []common.Label{"added"}, []common.Label{"removed"}),
36 }
37
38 for _, op := range good {
39 if err := op.Validate(); err != nil {
40 t.Fatal(err)
41 }
42 }
43
44 bad := []Operation{
45 // opbase
46 NewSetStatusOp(makeIdentity(t, "", "rene@descartes.fr"), unix, common.ClosedStatus),
47 NewSetStatusOp(makeIdentity(t, "René Descartes\u001b", "rene@descartes.fr"), unix, common.ClosedStatus),
48 NewSetStatusOp(makeIdentity(t, "René Descartes", "rene@descartes.fr\u001b"), unix, common.ClosedStatus),
49 NewSetStatusOp(makeIdentity(t, "René \nDescartes", "rene@descartes.fr"), unix, common.ClosedStatus),
50 NewSetStatusOp(makeIdentity(t, "René Descartes", "rene@\ndescartes.fr"), unix, common.ClosedStatus),
51 &CreateOperation{OpBase: dag.NewOpBase(CreateOp, rene, 0),
52 Title: "title",
53 Message: "message",
54 },
55
56 NewCreateOp(rene, unix, "multi\nline", "message", nil),
57 NewCreateOp(rene, unix, "title", "message", []repository.Hash{repository.Hash("invalid")}),
58 NewCreateOp(rene, unix, "title\u001b", "message", nil),
59 NewCreateOp(rene, unix, "title", "message\u001b", nil),
60 NewSetTitleOp(rene, unix, "multi\nline", "title1"),
61 NewSetTitleOp(rene, unix, "title", "multi\nline"),
62 NewSetTitleOp(rene, unix, "title\u001b", "title2"),
63 NewSetTitleOp(rene, unix, "title", "title2\u001b"),
64 NewAddCommentOp(rene, unix, "message\u001b", nil),
65 NewAddCommentOp(rene, unix, "message", []repository.Hash{repository.Hash("invalid")}),
66 NewSetStatusOp(rene, unix, 1000),
67 NewSetStatusOp(rene, unix, 0),
68 NewLabelChangeOperation(rene, unix, []common.Label{}, []common.Label{}),
69 NewLabelChangeOperation(rene, unix, []common.Label{"multi\nline"}, []common.Label{}),
70 }
71
72 for i, op := range bad {
73 if err := op.Validate(); err == nil {
74 t.Fatal("validation should have failed", i, op)

Callers

nothing calls this directly

Calls 11

NewMockRepoClockFunction · 0.92
NewIdentityFunction · 0.92
NewOpBaseFunction · 0.92
HashTypeAlias · 0.92
NewCreateOpFunction · 0.85
NewSetTitleOpFunction · 0.85
NewAddCommentOpFunction · 0.85
NewSetStatusOpFunction · 0.85
NewLabelChangeOperationFunction · 0.85
FatalMethod · 0.80
ValidateMethod · 0.65

Tested by

no test coverage detected