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

Function TestOperationPackFiles

entity/dag/operation_pack_test.go:86–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestOperationPackFiles(t *testing.T) {
87 repo, author, _, resolver, def := makeTestContext()
88
89 blobHash1, err := repo.StoreData(randomData())
90 require.NoError(t, err)
91
92 blobHash2, err := repo.StoreData(randomData())
93 require.NoError(t, err)
94
95 opp := &operationPack{
96 Author: author,
97 Operations: []Operation{
98 newOp1(author, "foo", blobHash1, blobHash2),
99 newOp1(author, "foo", blobHash2),
100 },
101 CreateTime: 123,
102 EditTime: 456,
103 }
104
105 commitHash, err := opp.Write(def, repo)
106 require.NoError(t, err)
107
108 commit, err := repo.ReadCommit(commitHash)
109 require.NoError(t, err)
110
111 opp2, err := readOperationPack(def, repo, resolver, commit)
112 require.NoError(t, err)
113
114 for _, op := range opp.Operations {
115 // force the creation of the id
116 op.Id()
117 }
118 require.Equal(t, opp, opp2)
119
120 require.ElementsMatch(t, opp2.Operations[0].(OperationWithFiles).GetFiles(), []repository.Hash{
121 blobHash1,
122 blobHash2,
123 })
124 require.ElementsMatch(t, opp2.Operations[1].(OperationWithFiles).GetFiles(), []repository.Hash{
125 blobHash2,
126 })
127
128 tree, err := repo.ReadTree(commit.TreeHash)
129 require.NoError(t, err)
130
131 extraTreeHash, ok := repository.SearchTreeEntry(tree, extraEntryName)
132 require.True(t, ok)
133
134 extraTree, err := repo.ReadTree(extraTreeHash.Hash)
135 require.NoError(t, err)
136 require.ElementsMatch(t, extraTree, []repository.TreeEntry{
137 {
138 ObjectType: repository.Blob,
139 Hash: blobHash1,
140 Name: "file0",
141 },
142 {
143 ObjectType: repository.Blob,

Callers

nothing calls this directly

Calls 11

WriteMethod · 0.95
SearchTreeEntryFunction · 0.92
makeTestContextFunction · 0.85
newOp1Function · 0.85
readOperationPackFunction · 0.85
randomDataFunction · 0.70
StoreDataMethod · 0.65
ReadCommitMethod · 0.65
IdMethod · 0.65
GetFilesMethod · 0.65
ReadTreeMethod · 0.65

Tested by

no test coverage detected