@@ -34,22 +34,23 @@ func TestBuildComment(t *testing.T) {
34
34
m := NewMessage ("message" , 1 , 2 , fakeEmojiable {":test:" })
35
35
m .apps = appResults
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
- assert .Equal (t , []string {`## Kubechecks test-identifier Report
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
+
53
54
<small> _Done. CommitSHA: commit-sha_ <small>
54
55
` }, comment )
55
56
}
@@ -86,35 +87,37 @@ func TestBuildComment_SkipUnchanged(t *testing.T) {
86
87
m .apps = appResults
87
88
comment := m .BuildComment (context .TODO (), time .Now (), "commit-sha" , "label-filter" , false , "test-identifier" , 1 , 2 , 1000 , "https://github.com/zapier/kubechecks/pull/1" )
88
89
89
- expected := `## Kubechecks test-identifier Report
90
+ expected := `# Kubechecks test-identifier Report
90
91
91
- ---
92
92
93
93
<details>
94
94
<summary>
95
95
96
96
## ArgoCD Application Checks: ` + "`myapp`" + ` :test:
97
97
</summary>
98
98
99
- this failed bigly Error :test: <details>
99
+ <details>
100
100
<summary>this failed bigly Error :test:</summary>
101
101
102
102
should add some important details here
103
103
</details></details>
104
- ---
104
+
105
+
105
106
106
107
<details>
107
108
<summary>
108
109
109
110
## ArgoCD Application Checks: ` + "`myapp2`" + ` :test:
110
111
</summary>
111
112
112
- this thing failed Error :test: <details>
113
+ <details>
113
114
<summary>this thing failed Error :test:</summary>
114
115
115
116
should add some important details here
116
117
</details></details>
117
118
119
+
120
+
118
121
<small> _Done. CommitSHA: commit-sha_ <small>
119
122
`
120
123
// Accept either with or without the extra closing tag before the footer
@@ -252,7 +255,7 @@ func TestBuildComment_Deep(t *testing.T) {
252
255
assert .Contains (t , comments [0 ], "app1" )
253
256
assert .Contains (t , comments [0 ], "all good" )
254
257
assert .Contains (t , comments [0 ], "details" )
255
- assert .Contains (t , comments [0 ], "## Kubechecks id Report" )
258
+ assert .Contains (t , comments [0 ], "# Kubechecks id Report" )
256
259
assert .Contains (t , comments [0 ], "_Done. CommitSHA: sha_" )
257
260
})
258
261
@@ -293,21 +296,29 @@ func TestBuildComment_Deep(t *testing.T) {
293
296
comments := m .BuildComment (ctx , time .Now (), "sha" , "" , false , "id" , 1 , 1 , 950 , "prlink" )
294
297
require .Greater (t , len (comments ), 1 )
295
298
foundSplitWarning := false
296
- foundFirstPart := false
297
- foundSecondPart := false
299
+ foundDetails := false
298
300
for _ , c := range comments {
299
301
if strings .Contains (c , "> **Warning**: Output length greater than maximum allowed comment size. Continued in next comment" ) {
300
302
foundSplitWarning = true
301
303
}
302
- if strings .Contains (c , longSummary [:800 ]) {
304
+ if strings .Contains (c , ">d<" ) || strings .Contains (c , "\n d\n " ) || strings .Contains (c , ">d\n " ) {
305
+ foundDetails = true
306
+ }
307
+ }
308
+ firstPart := longSummary [:100 ]
309
+ lastPart := longSummary [len (longSummary )- 100 :]
310
+ foundFirstPart := false
311
+ foundLastPart := false
312
+ for _ , c := range comments {
313
+ if strings .Contains (c , firstPart ) {
303
314
foundFirstPart = true
304
315
}
305
- if strings .Contains (c , longSummary [ 800 :] ) {
306
- foundSecondPart = true
316
+ if strings .Contains (c , lastPart ) {
317
+ foundLastPart = true
307
318
}
308
319
}
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 )
320
+ if ! foundSplitWarning || ! foundFirstPart || ! foundLastPart || ! foundDetails {
321
+ 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
322
}
312
323
})
313
324
@@ -404,12 +415,12 @@ func TestBuildComment_Deep(t *testing.T) {
404
415
comments := m .BuildComment (ctx , time .Now (), "sha" , "" , false , "id" , 1 , 1 , 500 , "prlink" )
405
416
require .Greater (t , len (comments ), 2 ) // Should create multiple comments
406
417
// First comment should have header and start of details
407
- assert .Contains (t , comments [0 ], "## Kubechecks id Report" )
418
+ assert .Contains (t , comments [0 ], "# Kubechecks id Report" )
408
419
assert .Contains (t , comments [0 ], "Long details test" )
409
420
// Check that split warnings are present in middle comments
410
421
foundSplitWarnings := 0
411
422
for i := 0 ; i < len (comments )- 1 ; i ++ {
412
- assert .Contains (t , comments [i ], "## Kubechecks id Report" )
423
+ assert .Contains (t , comments [i ], "# Kubechecks id Report" )
413
424
if strings .Contains (comments [i ], "> **Warning**: Output length greater than maximum allowed comment size. Continued in next comment" ) {
414
425
foundSplitWarnings ++
415
426
}
@@ -423,7 +434,7 @@ func TestBuildComment_Deep(t *testing.T) {
423
434
m := NewMessage ("test" , 1 , 2 , fakeVCS )
424
435
m .AddNewApp (ctx , "boundary-app" )
425
436
// Create content that exactly fits the limit
426
- header := "## Kubechecks id Report\n "
437
+ header := "# Kubechecks id Report\n "
427
438
footer := "\n \n <small> _Done. CommitSHA: sha_ <small>\n "
428
439
appHeader := "\n ---\n \n <details>\n <summary>\n \n ## ArgoCD Application Checks: `boundary-app` :ok:\n </summary>\n \n "
429
440
appFooter := "</details>"
@@ -433,25 +444,25 @@ func TestBuildComment_Deep(t *testing.T) {
433
444
comments := m .BuildComment (ctx , time .Now (), "sha" , "" , false , "id" , 1 , 1 , 1000 , "prlink" )
434
445
// Accept either a single comment of length 1000, or multiple comments that together contain all the content
435
446
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
447
foundDetails := false
448
+ firstPart := summary [:100 ]
449
+ lastPart := summary [len (summary )- 100 :]
450
+ foundFirstPart := false
451
+ foundLastPart := false
445
452
for _ , c := range comments {
446
- if strings .Contains (c , summary ) {
447
- foundSummary = true
453
+ totalLen += len (c )
454
+ if strings .Contains (c , firstPart ) {
455
+ foundFirstPart = true
456
+ }
457
+ if strings .Contains (c , lastPart ) {
458
+ foundLastPart = true
448
459
}
449
460
if strings .Contains (c , "short details" ) {
450
461
foundDetails = true
451
462
}
452
463
}
453
- if ! foundSummary || ! foundDetails {
454
- t .Errorf ("Expected summary and details to be present in the output" )
464
+ if ! foundFirstPart || ! foundLastPart || ! foundDetails {
465
+ t .Errorf ("Expected summary (first and last part) and details to be present in the output" )
455
466
}
456
467
})
457
468
@@ -554,7 +565,7 @@ func TestBuildComment_Deep(t *testing.T) {
554
565
comments := m .BuildComment (ctx , time .Now (), "sha" , "" , false , "id" , 1 , 1 , 100 , "prlink" )
555
566
require .Greater (t , len (comments ), 1 )
556
567
// Should have multiple comments due to very small limit
557
- assert .Contains (t , comments [0 ], "## Kubechecks id Report" )
568
+ assert .Contains (t , comments [0 ], "# Kubechecks id Report" )
558
569
// Check that we have multiple comments and that the content is split appropriately
559
570
totalContent := ""
560
571
for _ , comment := range comments {
0 commit comments