Skip to content

Commit 2017457

Browse files
committed
ensure depth tests checks that max depth was reached
before, if you lowered max depth, the test would still passed because we returned the expected error even though we didn't hit the expected depth. Signed-off-by: Taylor Silva <dev@taydev.net>
1 parent f8528c0 commit 2017457

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (g *GitHubClient) ResolveTagToCommitSHA(tagName string) (string, error) {
332332
currentSHA := *ref.Object.SHA
333333
maxDepth := 10
334334

335-
for i := 0; i < maxDepth; i++ {
335+
for range maxDepth {
336336
tag, res, err := g.client.Git.GetTag(context.TODO(), g.owner, g.repository, currentSHA)
337337
if err != nil {
338338
return "", fmt.Errorf("could not get tag object %q: %w", currentSHA, err)

github_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ var _ = Describe("GitHub Client", func() {
643643
)
644644

645645
// Add 11 tag-to-tag redirections (exceeding our max depth of 10)
646-
for i := 0; i < 11; i++ {
646+
for i := range 11 {
647647
currentSHA := fmt.Sprintf("tag-sha-%d", i)
648648
nextSHA := fmt.Sprintf("tag-sha-%d", i+1)
649649
server.AppendHandlers(
@@ -658,6 +658,7 @@ var _ = Describe("GitHub Client", func() {
658658
It("returns an error when max depth is exceeded", func() {
659659
_, err := client.ResolveTagToCommitSHA("deeply-nested")
660660

661+
Expect(len(server.ReceivedRequests())).To(Equal(11)) // first call + max depth value
661662
Expect(err).Should(HaveOccurred())
662663
Expect(err.Error()).To(ContainSubstring("exceeded maximum tag chain depth"))
663664
})

0 commit comments

Comments
 (0)