Skip to content

Commit

Permalink
Make sure we test for Pending Approval
Browse files Browse the repository at this point in the history
When the user is not allowed make sure we check the test are in Pending
Approval
  • Loading branch information
chmouel committed Jun 23, 2023
1 parent 8e4eb7f commit 688e38d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions test/gitea_access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func TestGiteaACLOrgPendingApproval(t *testing.T) {
assert.NilError(t, err)

topts.PullRequest = tgitea.CreateForkPullRequest(t, topts, secondcnx, "", "echo Hello from user "+topts.TargetRefName)
topts.CheckForStatus = "pending"
topts.CheckForStatus = "Skipped"
tgitea.WaitForStatus(t, topts, topts.PullRequest.Head.Sha, "", false)
topts.Regexp = regexp.MustCompile(`.*is skipping this commit.*`)
tgitea.WaitForPullRequestCommentMatch(t, topts)
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestGiteaACLCommentsAllowing(t *testing.T) {
assert.NilError(t, err)

topts.PullRequest = tgitea.CreateForkPullRequest(t, topts, secondcnx, "", "echo Hello from user "+topts.TargetRefName)
topts.CheckForStatus = "pending"
topts.CheckForStatus = "Skipped"
tgitea.WaitForStatus(t, topts, topts.PullRequest.Head.Sha, "", false)
topts.Regexp = regexp.MustCompile(`.*is skipping this commit.*`)
tgitea.WaitForPullRequestCommentMatch(t, topts)
Expand Down
1 change: 1 addition & 0 deletions test/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ func TestGiteaParamsOnRepoCRWithCustomConsole(t *testing.T) {
Value: "myconsole",
},
},
StatusOnlyLatest: true,
}
topts.TargetRefName = names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")
topts.TargetNS = topts.TargetRefName
Expand Down
23 changes: 20 additions & 3 deletions test/pkg/gitea/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
)

type TestOpts struct {
StatusOnlyLatest bool
OnOrg bool
NoPullRequestCreation bool
SkipEventsCheck bool
Expand Down Expand Up @@ -139,7 +140,7 @@ func TestPR(t *testing.T, topts *TestOpts) func() {
topts.ParamsRun.Clients.Log.Infof("PullRequest %s has been created", pr.HTMLURL)

if topts.CheckForStatus != "" {
WaitForStatus(t, topts, topts.TargetRefName, "", false)
WaitForStatus(t, topts, topts.TargetRefName, "", topts.StatusOnlyLatest)
}

if topts.Regexp != nil {
Expand Down Expand Up @@ -195,16 +196,32 @@ func WaitForStatus(t *testing.T, topts *TestOpts, ref, forcontext string, onlyla
return statuses[i].ID < statuses[j].ID
})
if onlylatest {
statuses = statuses[len(statuses)-1:]
if len(statuses) > 1 {
statuses = statuses[len(statuses)-1:]
} else {
time.Sleep(5 * time.Second)
continue
}
}
for _, cstatus := range statuses {
if topts.CheckForStatus == "Skipped" {
if strings.HasSuffix(cstatus.Description, "Pending approval") {
numstatus++
break
}
}
if cstatus.State == "pending" {
continue
}
if forcontext != "" && cstatus.Context != forcontext {
continue
}
assert.Equal(t, string(cstatus.State), topts.CheckForStatus)
statuscheck := topts.CheckForStatus
if statuscheck != "" && statuscheck != string(cstatus.State) {
if statuscheck != cstatus.Description {
t.Errorf("Status on SHA: %s is %s from %s", ref, cstatus.State, cstatus.Context)
}
}
topts.ParamsRun.Clients.Log.Infof("Status on SHA: %s is %s from %s", ref, cstatus.State, cstatus.Context)
numstatus++
}
Expand Down

0 comments on commit 688e38d

Please sign in to comment.