aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/operation_pack_test.go
blob: ad2a985967c91d76d6b7f5743c50986ae81ed472 (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
package dag

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestOperationPackReadWrite(t *testing.T) {
	repo, id1, _, def := makeTestContext()

	opp := &operationPack{
		Author: id1,
		Operations: []Operation{
			newOp1(id1, "foo"),
			newOp2(id1, "bar"),
		},
		CreateTime: 123,
		EditTime:   456,
	}

	commitHash, err := opp.Write(def, repo)
	require.NoError(t, err)

	commit, err := repo.ReadCommit(commitHash)
	require.NoError(t, err)

	opp2, err := readOperationPack(def, repo, commit)
	require.NoError(t, err)

	require.Equal(t, opp, opp2)

	// make sure we get the same Id with the same data
	opp3 := &operationPack{
		Author: id1,
		Operations: []Operation{
			newOp1(id1, "foo"),
			newOp2(id1, "bar"),
		},
		CreateTime: 123,
		EditTime:   456,
	}
	require.Equal(t, opp.Id(), opp3.Id())
}