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

Function TestTagForeach

tag_test.go:122–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestTagForeach(t *testing.T) {
123 t.Parallel()
124 repo := createTestRepo(t)
125 defer cleanupTestRepo(t, repo)
126
127 commitID, _ := seedTestRepo(t, repo)
128
129 commit, err := repo.LookupCommit(commitID)
130 checkFatal(t, err)
131
132 tag1 := createTag(t, repo, commit, "v1.0.1", "Release v1.0.1")
133
134 commitID, _ = updateReadme(t, repo, "Release version 2")
135
136 commit, err = repo.LookupCommit(commitID)
137 checkFatal(t, err)
138
139 tag2 := createTag(t, repo, commit, "v2.0.0", "Release v2.0.0")
140
141 expectedNames := []string{
142 "refs/tags/v1.0.1",
143 "refs/tags/v2.0.0",
144 }
145 actualNames := []string{}
146 expectedOids := []string{
147 tag1.String(),
148 tag2.String(),
149 }
150 actualOids := []string{}
151
152 err = repo.Tags.Foreach(func(name string, id *Oid) error {
153 actualNames = append(actualNames, name)
154 actualOids = append(actualOids, id.String())
155 return nil
156 })
157 checkFatal(t, err)
158
159 compareStringList(t, expectedNames, actualNames)
160 compareStringList(t, expectedOids, actualOids)
161
162 fakeErr := errors.New("fake error")
163
164 err = repo.Tags.Foreach(func(name string, id *Oid) error {
165 return fakeErr
166 })
167
168 if err != fakeErr {
169 t.Fatalf("Tags.Foreach() did not return the expected error, got %v", err)
170 }
171}
172
173func compareStrings(t *testing.T, expected, value string) {
174 if value != expected {

Callers

nothing calls this directly

Calls 10

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
checkFatalFunction · 0.85
createTagFunction · 0.85
updateReadmeFunction · 0.85
compareStringListFunction · 0.85
LookupCommitMethod · 0.80
StringMethod · 0.45
ForeachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…