MCPcopy Index your code
hub / github.com/git-bug/git-bug / SerializeRoundTripTest

Function SerializeRoundTripTest

entity/dag/operation_testing.go:17–43  ·  view source on GitHub ↗

SerializeRoundTripTest realize a marshall/unmarshall round-trip in the same condition as with OperationPack, and check if the recovered operation is identical.

(
	t *testing.T,
	unmarshaler OperationUnmarshaler,
	maker func(author identity.Interface, unixTime int64) (OpT, entity.Resolvers),
)

Source from the content-addressed store, hash-verified

15// SerializeRoundTripTest realize a marshall/unmarshall round-trip in the same condition as with OperationPack,
16// and check if the recovered operation is identical.
17func SerializeRoundTripTest[OpT Operation](
18 t *testing.T,
19 unmarshaler OperationUnmarshaler,
20 maker func(author identity.Interface, unixTime int64) (OpT, entity.Resolvers),
21) {
22 repo := repository.NewMockRepo()
23
24 rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
25 require.NoError(t, err)
26
27 op, resolvers := maker(rene, time.Now().Unix())
28 // enforce having an id
29 op.Id()
30
31 data, err := json.Marshal(op)
32 require.NoError(t, err)
33
34 after, err := unmarshaler(data, resolvers)
35 require.NoError(t, err)
36
37 // Set the id from the serialized data
38 after.setId(entity.DeriveId(data))
39 // Set the author, as OperationPack would do
40 after.setAuthor(rene)
41
42 require.Equal(t, op, after)
43}

Callers 8

TestAddCommentSerializeFunction · 0.92
TestSetStatusSerializeFunction · 0.92
TestEditCommentSerializeFunction · 0.92
TestCreateSerializeFunction · 0.92
TestLabelChangeSerializeFunction · 0.92
TestSetTitleSerializeFunction · 0.92
TestSetMetadataSerializeFunction · 0.85
TestNoopSerializeFunction · 0.85

Calls 7

NewMockRepoFunction · 0.92
NewIdentityFunction · 0.92
DeriveIdFunction · 0.92
unmarshalerFunction · 0.85
IdMethod · 0.65
setIdMethod · 0.65
setAuthorMethod · 0.65

Tested by 8

TestAddCommentSerializeFunction · 0.74
TestSetStatusSerializeFunction · 0.74
TestEditCommentSerializeFunction · 0.74
TestCreateSerializeFunction · 0.74
TestLabelChangeSerializeFunction · 0.74
TestSetTitleSerializeFunction · 0.74
TestSetMetadataSerializeFunction · 0.68
TestNoopSerializeFunction · 0.68