aboutsummaryrefslogtreecommitdiffstats
path: root/tests/operation_pack_test.go
blob: d7393c2932a4452794b82097e54a9e463b84d63b (plain) (blame)
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
package tests

import (
	"encoding/json"
	"reflect"
	"testing"

	"github.com/MichaelMure/git-bug/bug"
	"github.com/MichaelMure/git-bug/operations"
	"github.com/MichaelMure/git-bug/util/git"
)

func TestOperationPackSerialize(t *testing.T) {
	opp := &bug.OperationPack{}

	opp.Append(createOp)
	opp.Append(setTitleOp)
	opp.Append(addCommentOp)
	opp.Append(setStatusOp)
	opp.Append(labelChangeOp)

	opMeta := operations.NewCreateOp(rene, "title", "message", nil)
	opMeta.SetMetadata("key", "value")
	opp.Append(opMeta)

	if len(opMeta.Metadata) != 1 {
		t.Fatal()
	}

	opFile := operations.NewCreateOp(rene, "title", "message", []git.Hash{
		"abcdef",
		"ghijkl",
	})
	opp.Append(opFile)

	if len(opFile.Files) != 2 {
		t.Fatal()
	}

	data, err := json.Marshal(opp)
	if err != nil {
		t.Fatal(err)
	}

	var opp2 *bug.OperationPack
	err = json.Unmarshal(data, &opp2)
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(opp, opp2) {
		t.Fatalf("%v and %v are different", opp, opp2)
	}
}