MCPcopy Create free account
hub / github.com/git-bug/git-bug / TestSetMetadata

Function TestSetMetadata

entity/dag/op_set_metadata_test.go:29–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func TestSetMetadata(t *testing.T) {
30 snap := &snapshotMock{}
31
32 repo := repository.NewMockRepo()
33
34 rene, err := identity.NewIdentity(repo, "René Descartes", "rene@descartes.fr")
35 require.NoError(t, err)
36
37 unix := time.Now().Unix()
38
39 target1 := NewNoOpOp[*snapshotMock](1, rene, unix)
40 target1.SetMetadata("key", "value")
41 snap.ops = append(snap.ops, target1)
42
43 target2 := NewNoOpOp[*snapshotMock](1, rene, unix)
44 target2.SetMetadata("key2", "value2")
45 snap.ops = append(snap.ops, target2)
46
47 op1 := NewSetMetadataOp[*snapshotMock](2, rene, unix, target1.Id(), map[string]string{
48 "key": "override",
49 "key2": "value",
50 })
51
52 op1.Apply(snap)
53 snap.ops = append(snap.ops, op1)
54
55 target1Metadata := snap.AllOperations()[0].AllMetadata()
56 require.Len(t, target1Metadata, 2)
57 // original key is not overridden
58 require.Equal(t, target1Metadata["key"], "value")
59 // new key is set
60 require.Equal(t, target1Metadata["key2"], "value")
61
62 target2Metadata := snap.AllOperations()[1].AllMetadata()
63 require.Len(t, target2Metadata, 1)
64 require.Equal(t, target2Metadata["key2"], "value2")
65
66 op2 := NewSetMetadataOp[*snapshotMock](2, rene, unix, target2.Id(), map[string]string{
67 "key2": "value",
68 "key3": "value3",
69 })
70
71 op2.Apply(snap)
72 snap.ops = append(snap.ops, op2)
73
74 target1Metadata = snap.AllOperations()[0].AllMetadata()
75 require.Len(t, target1Metadata, 2)
76 require.Equal(t, target1Metadata["key"], "value")
77 require.Equal(t, target1Metadata["key2"], "value")
78
79 target2Metadata = snap.AllOperations()[1].AllMetadata()
80 require.Len(t, target2Metadata, 2)
81 // original key is not overridden
82 require.Equal(t, target2Metadata["key2"], "value2")
83 // new key is set
84 require.Equal(t, target2Metadata["key3"], "value3")
85
86 op3 := NewSetMetadataOp[*snapshotMock](2, rene, unix, target1.Id(), map[string]string{

Callers

nothing calls this directly

Calls 8

AllOperationsMethod · 0.95
NewMockRepoFunction · 0.92
NewIdentityFunction · 0.92
SetMetadataMethod · 0.65
IdMethod · 0.65
ApplyMethod · 0.65
AllMetadataMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected