(t *testing.T)
| 133 | } |
| 134 | |
| 135 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…