TODO: move to entity/dag?
(t *testing.T)
| 15 | // TODO: move to entity/dag? |
| 16 | |
| 17 | func 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) |
nothing calls this directly
no test coverage detected