aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operation_pack_test.go
blob: 8a8c7e62ba816974981e0d60bc73875a9536699f (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
package bug

import (
	"encoding/json"
	"testing"

	"github.com/MichaelMure/git-bug/util/git"
	"github.com/stretchr/testify/assert"
)

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

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

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

	assert.Equal(t, 1, len(opMeta.Metadata))

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

	assert.Equal(t, 2, len(opFile.Files))

	data, err := json.Marshal(opp)
	assert.NoError(t, err)

	var opp2 *OperationPack
	err = json.Unmarshal(data, &opp2)

	assert.NoError(t, err)
	assert.Equal(t, opp, opp2)
}