Skip to content

Commit 013bb73

Browse files
committed
fix: Improve SHA matching in repository status checks
Improved the logic for checking repository status by SHA. Previously, it only checked if any status entry contained the target SHA. Now, it verifies that a specific number of status entries match the target SHA, providing a more robust check. Additionally, it was enhanced to report all available SHAs if a matching SHA is not found, aiding in debugging. This change ensures that tests accurately reflect the expected status updates for a given commit. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent bd77a28 commit 013bb73

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

test/pkg/wait/check.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,28 @@ func Succeeded(ctx context.Context, t *testing.T, runcnx *params.Run, opts optio
4747
repo, err := runcnx.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(sopt.TargetNS).Get(ctx, sopt.TargetNS, v1.GetOptions{})
4848
assert.NilError(t, err)
4949

50+
assert.Assert(t, len(repo.Status) > 0, "repository status is empty")
5051
laststatus := repo.Status[len(repo.Status)-1]
5152
if sopt.SHA != "" {
53+
found := false
5254
for i := len(repo.Status) - 1; i >= 0; i-- {
5355
if repo.Status[i].SHA != nil && *repo.Status[i].SHA == sopt.SHA {
5456
laststatus = repo.Status[i]
57+
found = true
5558
break
5659
}
5760
}
61+
if !found {
62+
availableSHAs := make([]string, 0, len(repo.Status))
63+
for _, st := range repo.Status {
64+
if st.SHA != nil {
65+
availableSHAs = append(availableSHAs, *st.SHA)
66+
} else {
67+
availableSHAs = append(availableSHAs, "<nil>")
68+
}
69+
}
70+
assert.Assert(t, false, "no matching status found for SHA %s; available SHAs: %v", sopt.SHA, availableSHAs)
71+
}
5872
}
5973
assert.Equal(t, corev1.ConditionTrue, laststatus.Conditions[0].Status)
6074
if sopt.SHA != "" {

test/pkg/wait/wait.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,13 @@ func UntilRepositoryUpdated(ctx context.Context, clients clients.Clients, opts O
7575
clients.Log.Infof("Still waiting for repository status to be updated: %d/%d", len(repo.Status), opts.MinNumberStatus)
7676
time.Sleep(2 * time.Second)
7777
if opts.TargetSHA != "" {
78-
hasSHAStatus := false
78+
matchingStatuses := 0
7979
for _, s := range repo.Status {
8080
if s.SHA != nil && *s.SHA == opts.TargetSHA {
81-
hasSHAStatus = true
82-
break
81+
matchingStatuses++
8382
}
8483
}
85-
if !hasSHAStatus {
86-
return false, nil
87-
}
84+
return matchingStatuses > 0 && len(repo.Status) >= opts.MinNumberStatus, nil
8885
}
8986
return len(repo.Status) >= opts.MinNumberStatus, nil
9087
})

0 commit comments

Comments
 (0)