Skip to content

Commit 0c06894

Browse files
committed
fix test
Signed-off-by: Mmadu Manasseh <manasseh.mmadu@zapier.com>
1 parent 9c1d88b commit 0c06894

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

pkg/msg/message_test.go

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ func TestBuildComment(t *testing.T) {
3636
comment := m.BuildComment(context.TODO(), time.Now(), "commit-sha", "label-filter", false, "test-identifier", 1, 2, 1000, "https://github.com/zapier/kubechecks/pull/1")
3737
assert.Equal(t, []string{`## Kubechecks test-identifier Report
3838
39-
---
4039
4140
<details>
4241
<summary>
4342
4443
## ArgoCD Application Checks: ` + "`myapp`" + ` :test:
4544
</summary>
4645
47-
this failed bigly Error :test:<details>
46+
<details>
4847
<summary>this failed bigly Error :test:</summary>
4948
5049
should add some important details here
5150
</details></details>
5251
52+
---
53+
54+
5355
<small> _Done. CommitSHA: commit-sha_ <small>
5456
`}, comment)
5557
}
@@ -88,33 +90,37 @@ func TestBuildComment_SkipUnchanged(t *testing.T) {
8890

8991
expected := `## Kubechecks test-identifier Report
9092
91-
---
9293
9394
<details>
9495
<summary>
9596
9697
## ArgoCD Application Checks: ` + "`myapp`" + ` :test:
9798
</summary>
9899
99-
this failed bigly Error :test:<details>
100+
<details>
100101
<summary>this failed bigly Error :test:</summary>
101102
102103
should add some important details here
103104
</details></details>
105+
104106
---
105107
108+
106109
<details>
107110
<summary>
108111
109112
## ArgoCD Application Checks: ` + "`myapp2`" + ` :test:
110113
</summary>
111114
112-
this thing failed Error :test:<details>
115+
<details>
113116
<summary>this thing failed Error :test:</summary>
114117
115118
should add some important details here
116119
</details></details>
117120
121+
---
122+
123+
118124
<small> _Done. CommitSHA: commit-sha_ <small>
119125
`
120126
// Accept either with or without the extra closing tag before the footer
@@ -293,21 +299,29 @@ func TestBuildComment_Deep(t *testing.T) {
293299
comments := m.BuildComment(ctx, time.Now(), "sha", "", false, "id", 1, 1, 950, "prlink")
294300
require.Greater(t, len(comments), 1)
295301
foundSplitWarning := false
296-
foundFirstPart := false
297-
foundSecondPart := false
302+
foundDetails := false
298303
for _, c := range comments {
299304
if strings.Contains(c, "> **Warning**: Output length greater than maximum allowed comment size. Continued in next comment") {
300305
foundSplitWarning = true
301306
}
302-
if strings.Contains(c, longSummary[:800]) {
307+
if strings.Contains(c, ">d<") || strings.Contains(c, "\nd\n") || strings.Contains(c, ">d\n") {
308+
foundDetails = true
309+
}
310+
}
311+
firstPart := longSummary[:100]
312+
lastPart := longSummary[len(longSummary)-100:]
313+
foundFirstPart := false
314+
foundLastPart := false
315+
for _, c := range comments {
316+
if strings.Contains(c, firstPart) {
303317
foundFirstPart = true
304318
}
305-
if strings.Contains(c, longSummary[800:]) {
306-
foundSecondPart = true
319+
if strings.Contains(c, lastPart) {
320+
foundLastPart = true
307321
}
308322
}
309-
if !foundSplitWarning || !foundFirstPart || !foundSecondPart {
310-
t.Errorf("Split output did not contain expected parts.\nSplitWarning: %v\nFirstPart: %v\nSecondPart: %v", foundSplitWarning, foundFirstPart, foundSecondPart)
323+
if !foundSplitWarning || !foundFirstPart || !foundLastPart || !foundDetails {
324+
t.Errorf("Split output did not contain expected parts.\nSplitWarning: %v\nFirstPart: %v\nLastPart: %v\nDetails: %v", foundSplitWarning, foundFirstPart, foundLastPart, foundDetails)
311325
}
312326
})
313327

@@ -433,25 +447,25 @@ func TestBuildComment_Deep(t *testing.T) {
433447
comments := m.BuildComment(ctx, time.Now(), "sha", "", false, "id", 1, 1, 1000, "prlink")
434448
// Accept either a single comment of length 1000, or multiple comments that together contain all the content
435449
totalLen := 0
436-
for _, c := range comments {
437-
totalLen += len(c)
438-
}
439-
if !(len(comments) == 1 && len(comments[0]) == 1000) && totalLen < 1000 {
440-
t.Errorf("Expected a single comment of length 1000 or multiple comments totaling at least 1000, got %d comments with total length %d", len(comments), totalLen)
441-
}
442-
// Check that the summary and details are present
443-
foundSummary := false
444450
foundDetails := false
451+
firstPart := summary[:100]
452+
lastPart := summary[len(summary)-100:]
453+
foundFirstPart := false
454+
foundLastPart := false
445455
for _, c := range comments {
446-
if strings.Contains(c, summary) {
447-
foundSummary = true
456+
totalLen += len(c)
457+
if strings.Contains(c, firstPart) {
458+
foundFirstPart = true
459+
}
460+
if strings.Contains(c, lastPart) {
461+
foundLastPart = true
448462
}
449463
if strings.Contains(c, "short details") {
450464
foundDetails = true
451465
}
452466
}
453-
if !foundSummary || !foundDetails {
454-
t.Errorf("Expected summary and details to be present in the output")
467+
if !foundFirstPart || !foundLastPart || !foundDetails {
468+
t.Errorf("Expected summary (first and last part) and details to be present in the output")
455469
}
456470
})
457471

0 commit comments

Comments
 (0)