1package tests
2
3import (
4 "encoding/json"
5 "reflect"
6 "testing"
7
8 "github.com/MichaelMure/git-bug/bug"
9 "github.com/MichaelMure/git-bug/operations"
10 "github.com/MichaelMure/git-bug/util/git"
11)
12
13func TestOperationPackSerialize(t *testing.T) {
14 opp := &bug.OperationPack{}
15
16 opp.Append(createOp)
17 opp.Append(setTitleOp)
18 opp.Append(addCommentOp)
19 opp.Append(setStatusOp)
20 opp.Append(labelChangeOp)
21
22 opMeta := operations.NewCreateOp(rene, unix, "title", "message", nil)
23 opMeta.SetMetadata("key", "value")
24 opp.Append(opMeta)
25
26 if len(opMeta.Metadata) != 1 {
27 t.Fatal()
28 }
29
30 opFile := operations.NewCreateOp(rene, unix, "title", "message", []git.Hash{
31 "abcdef",
32 "ghijkl",
33 })
34 opp.Append(opFile)
35
36 if len(opFile.Files) != 2 {
37 t.Fatal()
38 }
39
40 data, err := json.Marshal(opp)
41 if err != nil {
42 t.Fatal(err)
43 }
44
45 var opp2 *bug.OperationPack
46 err = json.Unmarshal(data, &opp2)
47 if err != nil {
48 t.Fatal(err)
49 }
50
51 if !reflect.DeepEqual(opp, opp2) {
52 t.Fatalf("%v and %v are different", opp, opp2)
53 }
54}