(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func 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 | |
| 173 | func compareStrings(t *testing.T, expected, value string) { |
| 174 | if value != expected { |
nothing calls this directly
no test coverage detected
searching dependent graphs…