Skip to content

Commit a994198

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions/setup-go-6.3.0
2 parents 8db326b + 093ef51 commit a994198

File tree

3 files changed

+33
-92
lines changed

3 files changed

+33
-92
lines changed

test/github_pullrequest_test.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ package test
44

55
import (
66
"context"
7-
"crypto/sha256"
8-
"encoding/hex"
97
"fmt"
108
"os"
119
"regexp"
@@ -30,27 +28,10 @@ import (
3028
"github.com/tektoncd/pipeline/pkg/names"
3129
"gotest.tools/v3/assert"
3230
"gotest.tools/v3/assert/cmp"
33-
"gotest.tools/v3/golden"
3431
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3532
"knative.dev/pkg/apis"
3633
)
3734

38-
func compactCommentTimestamp(ts github.Timestamp) string {
39-
if ts.IsZero() {
40-
return "unknown"
41-
}
42-
return ts.UTC().Format(time.RFC3339)
43-
}
44-
45-
func commentBodyHash(body string) string {
46-
sum := sha256.Sum256([]byte(body))
47-
digest := hex.EncodeToString(sum[:])
48-
if len(digest) > 12 {
49-
return digest[:12]
50-
}
51-
return digest
52-
}
53-
5435
func TestGithubGHEPullRequestBasic(t *testing.T) {
5536
ctx := context.Background()
5637
g := &tgithub.PRTest{
@@ -188,78 +169,6 @@ func TestGithubPullRequestWebhook(t *testing.T) {
188169
defer g.TearDown(ctx, t)
189170
}
190171

191-
func TestGithubGHEPullRequestBadYaml(t *testing.T) {
192-
ctx := context.Background()
193-
g := &tgithub.PRTest{
194-
Label: "Github PullRequest Bad Yaml",
195-
YamlFiles: []string{"testdata/failures/bad-yaml.yaml"},
196-
GHE: true,
197-
NoStatusCheck: true,
198-
}
199-
g.RunPullRequest(ctx, t)
200-
defer g.TearDown(ctx, t)
201-
202-
maxLoop := 10
203-
for i := 0; i < maxLoop; i++ {
204-
comments, _, err := g.Provider.Client().Issues.ListComments(
205-
ctx, g.Options.Organization, g.Options.Repo, g.PRNumber,
206-
&github.IssueListCommentsOptions{})
207-
assert.NilError(t, err)
208-
209-
if len(comments) > 0 {
210-
if len(comments) > 1 {
211-
for _, comment := range comments {
212-
g.Cnx.Clients.Log.Infof("duplicate comment diagnostic: comment_id=%d created_at=%s updated_at=%s author_login=%s body_hash=%s body_len=%d",
213-
comment.GetID(),
214-
compactCommentTimestamp(comment.GetCreatedAt()),
215-
compactCommentTimestamp(comment.GetUpdatedAt()),
216-
comment.GetUser().GetLogin(),
217-
commentBodyHash(comment.GetBody()),
218-
len(comment.GetBody()))
219-
}
220-
221-
const recheckAttempts = 5
222-
for attempt := 1; attempt <= recheckAttempts && len(comments) > 1; attempt++ {
223-
g.Cnx.Clients.Log.Infof("recheck duplicate comments attempt=%d/%d current_count=%d", attempt, recheckAttempts, len(comments))
224-
time.Sleep(2 * time.Second)
225-
comments, _, err = g.Provider.Client().Issues.ListComments(
226-
ctx, g.Options.Organization, g.Options.Repo, g.PRNumber,
227-
&github.IssueListCommentsOptions{})
228-
assert.NilError(t, err)
229-
}
230-
231-
if len(comments) > 1 {
232-
commentSummaries := make([]string, 0, len(comments))
233-
for _, comment := range comments {
234-
commentSummaries = append(commentSummaries,
235-
fmt.Sprintf("%d(created=%s updated=%s)",
236-
comment.GetID(),
237-
compactCommentTimestamp(comment.GetCreatedAt()),
238-
compactCommentTimestamp(comment.GetUpdatedAt())))
239-
}
240-
assert.Assert(t, len(comments) == 1,
241-
"Should have only one comment created after rechecks, count=%d comments=%s",
242-
len(comments), strings.Join(commentSummaries, ", "))
243-
}
244-
}
245-
246-
if len(comments) == 0 {
247-
g.Cnx.Clients.Log.Infof("No comments after duplicate recheck, continuing wait loop %d/%d", i, maxLoop)
248-
time.Sleep(6 * time.Second)
249-
continue
250-
}
251-
252-
golden.Assert(t, comments[0].GetBody(), strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-"))
253-
return
254-
}
255-
256-
g.Cnx.Clients.Log.Infof("Looping %d/%d waiting for a comment to appear", i, maxLoop)
257-
time.Sleep(6 * time.Second)
258-
}
259-
260-
t.Fatal("No comments with the pipelinerun error found on the pull request")
261-
}
262-
263172
func TestGithubGHEInvalidCELExpressionReportingOnPR(t *testing.T) {
264173
ctx := context.Background()
265174
g := &tgithub.PRTest{

test/gitlab_merge_request_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"fmt"
88
"regexp"
9+
"strings"
910
"testing"
1011
"time"
1112

@@ -24,6 +25,7 @@ import (
2425
"github.com/tektoncd/pipeline/pkg/names"
2526
clientGitlab "gitlab.com/gitlab-org/api/client-go"
2627
"gotest.tools/v3/assert"
28+
"gotest.tools/v3/golden"
2729
corev1 "k8s.io/api/core/v1"
2830
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2931
"k8s.io/apimachinery/pkg/util/wait"
@@ -426,6 +428,36 @@ func TestGitlabMergeRequestOnUpdateAtAndLabelChange(t *testing.T) {
426428
}
427429
}
428430

431+
func TestGitlabMergeRequestBadYaml(t *testing.T) {
432+
topts := &tgitlab.TestOpts{
433+
TargetEvent: triggertype.PullRequest.String(),
434+
YAMLFiles: map[string]string{
435+
".tekton/bad-yaml.yaml": "testdata/failures/bad-yaml.yaml",
436+
},
437+
}
438+
_, cleanup := tgitlab.TestMR(t, topts)
439+
defer cleanup()
440+
441+
maxLoop := 10
442+
for i := 0; i < maxLoop; i++ {
443+
notes, _, err := topts.GLProvider.Client().Notes.ListMergeRequestNotes(topts.ProjectID, int64(topts.MRNumber), nil)
444+
assert.NilError(t, err)
445+
446+
for _, note := range notes {
447+
if note.System {
448+
continue
449+
}
450+
golden.Assert(t, note.Body, strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-"))
451+
return
452+
}
453+
454+
topts.ParamsRun.Clients.Log.Infof("Looping %d/%d waiting for a comment to appear", i, maxLoop)
455+
time.Sleep(6 * time.Second)
456+
}
457+
458+
t.Fatal("No comments with the pipelinerun error found on the merge request")
459+
}
460+
429461
func TestGitlabMergeRequestValidationErrorsFromFork(t *testing.T) {
430462
topts := &tgitlab.TestOpts{
431463
NoMRCreation: true,

test/testdata/TestGithubGHEPullRequestBadYaml.golden renamed to test/testdata/TestGitlabMergeRequestBadYaml.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
| PipelineRun | Error |
55
|------|-------|
6-
| bad-yaml.yaml | `yaml validation error: line 3: could not find expected ':'` |
6+
| .tekton/bad-yaml.yaml | `yaml validation error: line 3: could not find expected ':'` |

0 commit comments

Comments
 (0)