@@ -36,20 +36,22 @@ func TestBuildComment(t *testing.T) {
36
36
comment := m .BuildComment (context .TODO (), time .Now (), "commit-sha" , "label-filter" , false , "test-identifier" , 1 , 2 , 1000 , "https://github.com/zapier/kubechecks/pull/1" )
37
37
assert .Equal (t , []string {`## Kubechecks test-identifier Report
38
38
39
- ---
40
39
41
40
<details>
42
41
<summary>
43
42
44
43
## ArgoCD Application Checks: ` + "`myapp`" + ` :test:
45
44
</summary>
46
45
47
- this failed bigly Error :test: <details>
46
+ <details>
48
47
<summary>this failed bigly Error :test:</summary>
49
48
50
49
should add some important details here
51
50
</details></details>
52
51
52
+ ---
53
+
54
+
53
55
<small> _Done. CommitSHA: commit-sha_ <small>
54
56
` }, comment )
55
57
}
@@ -88,33 +90,37 @@ func TestBuildComment_SkipUnchanged(t *testing.T) {
88
90
89
91
expected := `## Kubechecks test-identifier Report
90
92
91
- ---
92
93
93
94
<details>
94
95
<summary>
95
96
96
97
## ArgoCD Application Checks: ` + "`myapp`" + ` :test:
97
98
</summary>
98
99
99
- this failed bigly Error :test: <details>
100
+ <details>
100
101
<summary>this failed bigly Error :test:</summary>
101
102
102
103
should add some important details here
103
104
</details></details>
105
+
104
106
---
105
107
108
+
106
109
<details>
107
110
<summary>
108
111
109
112
## ArgoCD Application Checks: ` + "`myapp2`" + ` :test:
110
113
</summary>
111
114
112
- this thing failed Error :test: <details>
115
+ <details>
113
116
<summary>this thing failed Error :test:</summary>
114
117
115
118
should add some important details here
116
119
</details></details>
117
120
121
+ ---
122
+
123
+
118
124
<small> _Done. CommitSHA: commit-sha_ <small>
119
125
`
120
126
// Accept either with or without the extra closing tag before the footer
@@ -293,21 +299,29 @@ func TestBuildComment_Deep(t *testing.T) {
293
299
comments := m .BuildComment (ctx , time .Now (), "sha" , "" , false , "id" , 1 , 1 , 950 , "prlink" )
294
300
require .Greater (t , len (comments ), 1 )
295
301
foundSplitWarning := false
296
- foundFirstPart := false
297
- foundSecondPart := false
302
+ foundDetails := false
298
303
for _ , c := range comments {
299
304
if strings .Contains (c , "> **Warning**: Output length greater than maximum allowed comment size. Continued in next comment" ) {
300
305
foundSplitWarning = true
301
306
}
302
- if strings .Contains (c , longSummary [:800 ]) {
307
+ if strings .Contains (c , ">d<" ) || strings .Contains (c , "\n d\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 ) {
303
317
foundFirstPart = true
304
318
}
305
- if strings .Contains (c , longSummary [ 800 :] ) {
306
- foundSecondPart = true
319
+ if strings .Contains (c , lastPart ) {
320
+ foundLastPart = true
307
321
}
308
322
}
309
- if ! foundSplitWarning || ! foundFirstPart || ! foundSecondPart {
310
- t .Errorf ("Split output did not contain expected parts.\n SplitWarning: %v\n FirstPart: %v\n SecondPart : %v" , foundSplitWarning , foundFirstPart , foundSecondPart )
323
+ if ! foundSplitWarning || ! foundFirstPart || ! foundLastPart || ! foundDetails {
324
+ t .Errorf ("Split output did not contain expected parts.\n SplitWarning: %v\n FirstPart: %v\n LastPart : %v\n Details: %v " , foundSplitWarning , foundFirstPart , foundLastPart , foundDetails )
311
325
}
312
326
})
313
327
@@ -433,25 +447,25 @@ func TestBuildComment_Deep(t *testing.T) {
433
447
comments := m .BuildComment (ctx , time .Now (), "sha" , "" , false , "id" , 1 , 1 , 1000 , "prlink" )
434
448
// Accept either a single comment of length 1000, or multiple comments that together contain all the content
435
449
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
444
450
foundDetails := false
451
+ firstPart := summary [:100 ]
452
+ lastPart := summary [len (summary )- 100 :]
453
+ foundFirstPart := false
454
+ foundLastPart := false
445
455
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
448
462
}
449
463
if strings .Contains (c , "short details" ) {
450
464
foundDetails = true
451
465
}
452
466
}
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" )
455
469
}
456
470
})
457
471
0 commit comments