MCPcopy Create free account
hub / github.com/libgit2/git2go / TestObjectPeel

Function TestObjectPeel

object_test.go:135–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

133}
134
135func TestObjectPeel(t *testing.T) {
136 t.Parallel()
137 repo := createTestRepo(t)
138 defer cleanupTestRepo(t, repo)
139
140 commitID, treeID := seedTestRepo(t, repo)
141
142 var obj *Object
143
144 commit, err := repo.LookupCommit(commitID)
145 checkFatal(t, err)
146
147 obj, err = commit.Peel(ObjectAny)
148 checkFatal(t, err)
149
150 if obj.Type() != ObjectTree {
151 t.Fatalf("Wrong object type when peeling a commit, expected tree, have %v", obj.Type())
152 }
153
154 obj, err = commit.Peel(ObjectTag)
155
156 if !IsErrorCode(err, ErrorCodeInvalidSpec) {
157 t.Fatalf("Wrong error when peeling a commit to a tag, expected ErrorCodeInvalidSpec, have %v", err)
158 }
159
160 tree, err := repo.LookupTree(treeID)
161 checkFatal(t, err)
162
163 obj, err = tree.Peel(ObjectAny)
164
165 if !IsErrorCode(err, ErrorCodeInvalidSpec) {
166 t.Fatalf("Wrong error when peeling a tree, expected ErrorCodeInvalidSpec, have %v", err)
167 }
168
169 entry := tree.EntryByName("README")
170
171 blob, err := repo.LookupBlob(entry.Id)
172 checkFatal(t, err)
173
174 obj, err = blob.Peel(ObjectAny)
175
176 if !IsErrorCode(err, ErrorCodeInvalidSpec) {
177 t.Fatalf("Wrong error when peeling a blob, expected ErrorCodeInvalidSpec, have %v", err)
178 }
179
180 tagID := createTestTag(t, repo, commit)
181
182 tag, err := repo.LookupTag(tagID)
183 checkFatal(t, err)
184
185 obj, err = tag.Peel(ObjectAny)
186 checkFatal(t, err)
187
188 if obj.Type() != ObjectCommit {
189 t.Fatalf("Wrong object type when peeling a tag, expected commit, have %v", obj.Type())
190 }
191
192 // TODO: Should test a tag that annotates a different object than a commit

Callers

nothing calls this directly

Calls 13

TypeMethod · 0.95
createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
checkFatalFunction · 0.85
IsErrorCodeFunction · 0.85
createTestTagFunction · 0.85
LookupCommitMethod · 0.80
LookupTreeMethod · 0.80
EntryByNameMethod · 0.80
LookupBlobMethod · 0.80
LookupTagMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…