Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/bitbucket_cloud_pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func TestBitbucketCloudPullRequestCancelInProgressMerged(t *testing.T) {
Namespace: targetNS,
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
TargetSHA: sha,
TargetSHA: []string{sha},
}
err = twait.UntilPipelineRunCreated(ctx, runcnx.Clients, waitOpts)
_, err = twait.UntilPipelineRunCreated(ctx, runcnx.Clients, waitOpts)
assert.NilError(t, err)

po := &bitbucket.PullRequestsOptions{
Expand Down
5 changes: 3 additions & 2 deletions test/gitea_access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/payload"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/scm"
twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -472,9 +473,9 @@ func TestGiteaPolicyAllowedOwnerFiles(t *testing.T) {
Namespace: topts.TargetNS,
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
TargetSHA: npr.Head.Sha,
TargetSHA: []string{npr.Head.Sha},
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
_, err = twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
time.Sleep(5 * time.Second) // β€œEvil does not sleep. It waits.” - Galadriel

Expand Down
72 changes: 37 additions & 35 deletions test/gitea_gitops_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

forgejo "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v3"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/keys"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
"github.com/openshift-pipelines/pipelines-as-code/pkg/opscomments"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
Expand All @@ -20,6 +21,7 @@ import (
pacrepo "github.com/openshift-pipelines/pipelines-as-code/test/pkg/repository"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/secret"
twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/names"
"gotest.tools/v3/assert"
)
Expand All @@ -44,10 +46,10 @@ func TestGiteaCancelRun(t *testing.T) {
Namespace: topts.TargetNS,
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
TargetSHA: []string{topts.PullRequest.Head.Sha},
}
_, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.Error(t, err, "pipelinerun has failed")
_, err := twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonCancelled, waitOpts)
assert.NilError(t, err)

tgitea.CheckIfPipelineRunsCancelled(t, topts)
}
Expand Down Expand Up @@ -100,33 +102,33 @@ func TestGiteaOnCommentAnnotation(t *testing.T) {
MinNumberStatus: 2,
PollTimeout: twait.DefaultTimeout,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
_, err = twait.UntilPipelineRunCreated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)

tgitea.PostCommentOnPullRequest(t, topts, triggerComment)
waitOpts.MinNumberStatus = 3
// now we should have only 3 status, the last one is the on comment match from the comment sent
// but should not have matched the pull request ones
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunCreated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), waitOpts.MinNumberStatus, fmt.Sprintf("should have only %d status", waitOpts.MinNumberStatus))
assert.Equal(t, *repo.Status[len(repo.Status)-1].EventType, opscomments.OnCommentEventType.String(), "should have a on comment event type")
assert.Equal(t, len(prs), waitOpts.MinNumberStatus, fmt.Sprintf("should have only %d status", waitOpts.MinNumberStatus))
assert.Equal(t, prs[len(prs)-1].Annotations[keys.EventType], opscomments.OnCommentEventType.String(), "should have a on comment event type")

last := repo.Status[len(repo.Status)-1]
last := prs[len(prs)-1]
twait.GoldenPodLog(context.Background(), t, topts.ParamsRun, topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName),
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.Name),
"step-task", strings.ReplaceAll(fmt.Sprintf("%s-pipelinerun-on-comment-annotation.golden", t.Name()), "/", "-"), 2, nil)

tgitea.PostCommentOnPullRequest(t, topts, fmt.Sprintf(`%s revision=main custom1=thisone custom2="another one" custom_no_initial_value="a \"quote\""`, triggerComment))
waitOpts.MinNumberStatus = 4
repo, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err = twait.UntilPipelineRunsFinished(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), waitOpts.MinNumberStatus, fmt.Sprintf("should have only %d status", waitOpts.MinNumberStatus))
assert.Equal(t, *repo.Status[len(repo.Status)-1].EventType, opscomments.OnCommentEventType.String(), "should have a on comment event type")
assert.Equal(t, len(prs), waitOpts.MinNumberStatus, fmt.Sprintf("should have only %d status", waitOpts.MinNumberStatus))
assert.Equal(t, prs[len(prs)-1].Annotations[keys.EventType], opscomments.OnCommentEventType.String(), "should have a on comment event type")
// now we should have only 3 status, the last one is the on comment match with an argument redefining the revision which is a standard parameter

last = repo.Status[len(repo.Status)-1]
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName), "step-task", regexp.Regexp{}, t.Name(), 2, nil)
last = prs[len(prs)-1]
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s", last.Name), "step-task", regexp.Regexp{}, t.Name(), 2, nil)
assert.NilError(t, err)
}

Expand Down Expand Up @@ -168,15 +170,15 @@ func TestGiteaOnCommentTestOverride(t *testing.T) {
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
}
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunsFinished(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 1, "should have exactly 1 status")
assert.Equal(t, *repo.Status[0].EventType, opscomments.OnCommentEventType.String(),
assert.Equal(t, len(prs), 1, "should have exactly 1 status")
assert.Equal(t, prs[0].Annotations[keys.EventType], opscomments.OnCommentEventType.String(),
"should have matched via on-comment annotation, not built-in /test handler")

last := repo.Status[0]
last := prs[0]
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName), "step-task",
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.Name), "step-task",
*regexp.MustCompile("custom1 is overridden"), "", 2, nil)
assert.NilError(t, err)
}
Expand Down Expand Up @@ -219,15 +221,15 @@ func TestGiteaTestPipelineRunExplicitlyWithTestComment(t *testing.T) {
PollTimeout: twait.DefaultTimeout,
}

repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunCreated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 1, "should have only 1 status")
assert.Equal(t, *repo.Status[0].EventType, opscomments.TestSingleCommentEventType.String(), "should have a test comment event in status")
assert.Assert(t, strings.HasPrefix(repo.Status[0].PipelineRunName, targetPrName+"-"),
"we didn't target the proper pipelinerun, we tested: %s", repo.Status[0].PipelineRunName)
assert.Equal(t, len(prs), 1, "should have only 1 status")
assert.Equal(t, prs[0].Annotations[keys.EventType], opscomments.TestSingleCommentEventType.String(), "should have a test comment event in status")
assert.Assert(t, strings.HasPrefix(prs[0].Name, targetPrName+"-"),
"we didn't target the proper pipelinerun, we tested: %s", prs[0].Name)

last := repo.Status[len(repo.Status)-1]
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName), "step-task", *regexp.MustCompile("custom is awesome"), "", 2, nil)
last := prs[len(prs)-1]
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s", last.Name), "step-task", *regexp.MustCompile("custom is awesome"), "", 2, nil)
assert.NilError(t, err)
}

Expand Down Expand Up @@ -266,21 +268,21 @@ func TestGiteaTestAll(t *testing.T) {
PollTimeout: twait.DefaultTimeout,
}

repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunCreated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
var hasPullRequest bool
var hasTestAll bool
for _, status := range repo.Status {
if *status.EventType == triggertype.PullRequest.String() {
for _, pr := range prs {
if pr.Annotations[keys.EventType] == triggertype.PullRequest.String() {
hasPullRequest = true
}
if *status.EventType == opscomments.TestAllCommentEventType.String() {
if pr.Annotations[keys.EventType] == opscomments.TestAllCommentEventType.String() {
hasTestAll = true
}
}
assert.Assert(t, hasPullRequest, "should have the initial pull request event in status")
assert.Assert(t, hasTestAll, "should have a test all comment event in status")
assert.Equal(t, len(repo.Status), 2, "should have only 2 status")
assert.Equal(t, len(prs), 2, "should have only 2 status")
}

func TestGiteaRetestCommentUpdate(t *testing.T) {
Expand Down Expand Up @@ -334,16 +336,16 @@ func TestGiteaRetestCommentUpdate(t *testing.T) {
PollTimeout: twait.DefaultTimeout,
}

repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunCreated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
var rt bool
for _, status := range repo.Status {
if *status.EventType == triggertype.PullRequest.String() {
for _, pr := range prs {
if pr.Annotations[keys.EventType] == triggertype.PullRequest.String() {
rt = true
}
}
assert.Assert(t, rt, "should have a retest all comment event in status")
assert.Equal(t, len(repo.Status), 2, "should have only 2 status")
assert.Equal(t, len(prs), 2, "should have only 2 status")

// Verify comment strategy: count pac-status comments.
comments, _, err := topts.GiteaCNX.Client().ListRepoIssueComments(
Expand Down
32 changes: 14 additions & 18 deletions test/gitea_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ func TestGiteaRetestPreservesSourceURL(t *testing.T) {
Namespace: topts.TargetNS,
MinNumberStatus: 2,
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
TargetSHA: []string{topts.PullRequest.Head.Sha},
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
_, err = twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
assert.NilError(t, twait.UntilMinPRAppeared(context.Background(), topts.ParamsRun.Clients, waitOpts, 2))

Expand Down Expand Up @@ -311,14 +311,14 @@ func TestGiteaGlobalRepoParams(t *testing.T) {
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
}
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
last := repo.Status[len(repo.Status)-1]
last := prs[len(prs)-1]
err = twait.RegexpMatchingInPodLog(
context.Background(),
topts.ParamsRun,
topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName),
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.Name),
"step-test-params-value",
regexp.Regexp{},
t.Name(),
Expand Down Expand Up @@ -390,14 +390,14 @@ func TestGiteaGlobalRepoUseLocalDef(t *testing.T) {
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
}
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
last := repo.Status[len(repo.Status)-1]
last := prs[len(prs)-1]
err = twait.RegexpMatchingInPodLog(
context.Background(),
topts.ParamsRun,
topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName),
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.Name),
"step-test-params-value",
regexp.Regexp{},
t.Name(),
Expand Down Expand Up @@ -480,14 +480,13 @@ func TestGiteaParamsOnRepoCR(t *testing.T) {
Namespace: topts.TargetNS,
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
TargetSHA: "",
}
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
prs, err := twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
assert.Assert(t, len(repo.Status) != 0)
assert.Assert(t, len(prs) != 0)
assert.NilError(t,
twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=params",
repo.Status[0].PipelineRunName), "step-test-params-value", *regexp.MustCompile(
prs[0].Name), "step-test-params-value", *regexp.MustCompile(
"I am the most KawaΔ« params\nSHHHHHHH\nFollow me on my ig #nofilter\n{{ no_match }}\nHey I show up from a payload match\n{{ secret_nothere }}\n{{ no_initial_value }}"), "", 2, nil))
}

Expand Down Expand Up @@ -538,9 +537,8 @@ my email is a true beauty and like groot, I AM pac`
Namespace: topts.TargetNS,
MinNumberStatus: 2, // 1 means 2 πŸ™ƒ
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
_, err = twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)

time.Sleep(5 * time.Second)
Expand Down Expand Up @@ -622,9 +620,8 @@ func TestGiteaParamsChangedFilesCEL(t *testing.T) {
Namespace: topts.TargetNS,
MinNumberStatus: 2, // 1 means 2 πŸ™ƒ
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
_, err = twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
time.Sleep(5 * time.Second)

Expand Down Expand Up @@ -669,9 +666,8 @@ func TestGiteaParamsChangedFilesCEL(t *testing.T) {
Namespace: topts.TargetNS,
MinNumberStatus: 4, // 1 means 2 πŸ™ƒ
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
_, err = twait.UntilPipelineRunHasReason(context.Background(), topts.ParamsRun.Clients, tektonv1.PipelineRunReasonSuccessful, waitOpts)
assert.NilError(t, err)
time.Sleep(5 * time.Second)

Expand Down
19 changes: 9 additions & 10 deletions test/gitea_retest_pruned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,18 @@ func TestGiteaRetestAfterPipelineRunPruning(t *testing.T) {
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
PollTimeout: twait.DefaultTimeout,
TargetSHA: formatting.CleanValueKubernetes(sha),
TargetSHA: []string{formatting.CleanValueKubernetes(sha)},
}, 2)
assert.NilError(t, err)

// Wait for repository to have at least 2 status entries
topts.ParamsRun.Clients.Log.Infof("Waiting for Repository status to have 2 entries")
_, err = twait.UntilRepositoryUpdated(ctx, topts.ParamsRun.Clients, twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 2,
PollTimeout: twait.DefaultTimeout,
TargetSHA: sha,
FailOnRepoCondition: "no-match",
// Wait for both PipelineRuns to finish (1 success + 1 failure)
topts.ParamsRun.Clients.Log.Infof("Waiting for 2 PipelineRuns to finish")
_, err = twait.UntilPipelineRunsFinished(ctx, topts.ParamsRun.Clients, twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 2,
PollTimeout: twait.DefaultTimeout,
TargetSHA: []string{sha},
})
assert.NilError(t, err)

Expand Down
Loading
Loading