Skip to content

Commit b750180

Browse files
authored
Switched to emoji for color-based emphasis (GoogleCloudPlatform#11861)
1 parent 859f73e commit b750180

File tree

4 files changed

+73
-77
lines changed

4 files changed

+73
-77
lines changed

.ci/magician/cmd/templates.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@ func color(color, text string) string {
88
if color == "" || text == "" {
99
return text
1010
}
11-
return fmt.Sprintf("$\\textcolor{%s}{\\textsf{%s}}$", color, text)
11+
var emoji string
12+
switch color {
13+
case "red":
14+
emoji = "🔴"
15+
case "yellow":
16+
emoji = "🟡"
17+
case "green":
18+
emoji = "🟢"
19+
default:
20+
return text
21+
}
22+
return fmt.Sprintf("%s %s", emoji, text)
1223
}

.ci/magician/cmd/templates_test.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@ func TestColor(t *testing.T) {
1515
name: "red",
1616
color: "red",
1717
text: "Test text",
18-
want: "$\\textcolor{red}{\\textsf{Test text}}$",
18+
want: "🔴 Test text",
19+
},
20+
{
21+
name: "yellow",
22+
color: "yellow",
23+
text: "Test text",
24+
want: "🟡 Test text",
1925
},
2026
{
2127
name: "green",
2228
color: "green",
2329
text: "Test text",
24-
want: "$\\textcolor{green}{\\textsf{Test text}}$",
30+
want: "🟢 Test text",
31+
},
32+
{
33+
name: "unsupported color",
34+
color: "mauve",
35+
text: "Test text",
36+
want: "Test text",
2537
},
2638
{
2739
name: "empty color",

.ci/magician/cmd/test_terraform_vcr.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ func runReplaying(runFullVCR bool, services map[string]struct{}, vt *vcr.Tester)
455455

456456
func handlePanics(prNumber, buildID, buildStatusTargetURL, mmCommitSha string, result vcr.Result, mode vcr.Mode, gh GithubClient) (bool, error) {
457457
if len(result.Panics) > 0 {
458-
comment := fmt.Sprintf(`$\textcolor{red}{\textsf{The provider crashed while running the VCR tests in %s mode}}$
459-
$\textcolor{red}{\textsf{Please fix it to complete your PR}}$
460-
View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-%s/artifacts/%s/build-log/%s_test.log)`, mode.Upper(), prNumber, buildID, mode.Lower())
458+
comment := color("red", fmt.Sprintf("The provider crashed while running the VCR tests in %s mode\n", mode.Upper()))
459+
comment += fmt.Sprintf(`Please fix it to complete your PR.
460+
View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-%s/artifacts/%s/build-log/%s_test.log)`, prNumber, buildID, mode.Lower())
461461
if err := gh.PostComment(prNumber, comment); err != nil {
462462
return true, fmt.Errorf("error posting comment: %v", err)
463463
}

.ci/magician/cmd/test_terraform_vcr_test.go

+44-71
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func TestWithoutReplayFailedTests(t *testing.T) {
469469
tests := []struct {
470470
name string
471471
data withoutReplayFailedTests
472-
want string
472+
wantContains []string
473473
}{
474474
{
475475
name: "with replay error",
@@ -478,29 +478,21 @@ func TestWithoutReplayFailedTests(t *testing.T) {
478478
BuildID: "build-123",
479479
PRNumber: "123",
480480
},
481-
want: strings.Join(
482-
[]string{
483-
"$\\textcolor{red}{\\textsf{Errors occurred during REPLAYING mode. Please fix them to complete your PR.}}$",
484-
"",
485-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_test.log)",
486-
},
487-
"\n",
488-
),
481+
wantContains: []string{
482+
color("red", "Errors occurred during REPLAYING mode. Please fix them to complete your PR."),
483+
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_test.log)",
484+
},
489485
},
490486
{
491487
name: "without replay error",
492488
data: withoutReplayFailedTests{
493489
BuildID: "build-123",
494490
PRNumber: "123",
495491
},
496-
want: strings.Join(
497-
[]string{
498-
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
499-
"",
500-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_test.log)",
501-
},
502-
"\n",
503-
),
492+
wantContains: []string{
493+
color("green", "All tests passed!"),
494+
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_test.log)",
495+
},
504496
},
505497
}
506498
for _, tc := range tests {
@@ -509,8 +501,10 @@ func TestWithoutReplayFailedTests(t *testing.T) {
509501
if err != nil {
510502
t.Fatalf("Failed to format comment: %v", err)
511503
}
512-
if diff := cmp.Diff(tc.want, got); diff != "" {
513-
t.Errorf("formatWithoutReplayFailedTests() returned unexpected difference (-want +got):\n%s", diff)
504+
for _, wc := range tc.wantContains {
505+
if !strings.Contains(got, wc) {
506+
t.Errorf("formatWithoutReplayFailedTests() returned %q, which does not contain %q", got, wc)
507+
}
514508
}
515509
})
516510
}
@@ -520,7 +514,7 @@ func TestRecordReplay(t *testing.T) {
520514
tests := []struct {
521515
name string
522516
data recordReplay
523-
want string
517+
wantContains []string
524518
}{
525519
{
526520
name: "ReplayingAfterRecordingResult has failed tests",
@@ -538,36 +532,23 @@ func TestRecordReplay(t *testing.T) {
538532
BuildID: "build-123",
539533
PRNumber: "123",
540534
},
541-
want: strings.Join(
542-
[]string{
543-
"$\\textcolor{green}{\\textsf{Tests passed during RECORDING mode:}}$", "`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/a.log)]",
544-
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
545-
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
546-
"$\\textcolor{red}{\\textsf{Tests failed when rerunning REPLAYING mode:}}$",
547-
"`b`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/b_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/replaying_after_recording/b.log)]",
548-
"`c`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/c_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/replaying_after_recording/c.log)]",
549-
"",
550-
"",
551-
"Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.",
552-
"",
553-
"Please fix these to complete your PR. If you believe these test failures to be incorrect or unrelated to your change, or if you have any questions, please raise the concern with your reviewer.",
554-
"",
555-
"",
556-
"---",
557-
"",
558-
"",
559-
"$\\textcolor{red}{\\textsf{Tests failed during RECORDING mode:}}$",
560-
"`d`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_build/d_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/d.log)]",
561-
"`e`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_build/e_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/e.log)]",
562-
"",
563-
"$\\textcolor{red}{\\textsf{Several tests got terminated during RECORDING mode.}}$",
564-
"$\\textcolor{red}{\\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$",
565-
"",
566-
"",
567-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording) for each test",
568-
},
569-
"\n",
570-
),
535+
wantContains: []string{
536+
color("green", "Tests passed during RECORDING mode:"),
537+
"`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/a.log)]",
538+
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
539+
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
540+
color("red", "Tests failed when rerunning REPLAYING mode:"),
541+
"`b`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/b_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/replaying_after_recording/b.log)]",
542+
"`c`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/replaying_build_after_recording/c_replaying_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/replaying_after_recording/c.log)]",
543+
"Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.",
544+
"Please fix these to complete your PR. If you believe these test failures to be incorrect or unrelated to your change, or if you have any questions, please raise the concern with your reviewer.",
545+
color("red", "Tests failed during RECORDING mode:"),
546+
"`d`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_build/d_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/d.log)]",
547+
"`e`[[Error message](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_build/e_recording_test.log)] [[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/e.log)]",
548+
color("red", "Several tests got terminated during RECORDING mode."),
549+
"Errors occurred during RECORDING mode. Please fix them to complete your PR.",
550+
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording) for each test",
551+
},
571552
},
572553
{
573554
name: "ReplayingAfterRecordingResult does not have failed tests",
@@ -582,25 +563,15 @@ func TestRecordReplay(t *testing.T) {
582563
BuildID: "build-123",
583564
PRNumber: "123",
584565
},
585-
want: strings.Join(
586-
[]string{
587-
"$\\textcolor{green}{\\textsf{Tests passed during RECORDING mode:}}$", "`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/a.log)]",
588-
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
589-
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
590-
"",
591-
"$\\textcolor{green}{\\textsf{No issues found for passed tests after REPLAYING rerun.}}$",
592-
"",
593-
"---",
594-
"",
595-
"",
596-
"",
597-
"",
598-
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
599-
"",
600-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording) for each test",
601-
},
602-
"\n",
603-
),
566+
wantContains: []string{
567+
color("green", "Tests passed during RECORDING mode:"),
568+
"`a`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/a.log)]",
569+
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
570+
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
571+
color("green", "No issues found for passed tests after REPLAYING rerun."),
572+
color("green", "All tests passed!"),
573+
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/build-log/recording_test.log) or the [debug log](https://console.cloud.google.com/storage/browser/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording) for each test",
574+
},
604575
},
605576
}
606577
for _, tc := range tests {
@@ -609,8 +580,10 @@ func TestRecordReplay(t *testing.T) {
609580
if err != nil {
610581
t.Fatalf("Failed to format comment: %v", err)
611582
}
612-
if diff := cmp.Diff(tc.want, got); diff != "" {
613-
t.Errorf("formatRecordReplay() returned unexpected difference (-want +got):\n%s", diff)
583+
for _, wc := range tc.wantContains {
584+
if !strings.Contains(got, wc) {
585+
t.Errorf("formatRecordReplay() returned %q, which does not contain %q", got, wc)
586+
}
614587
}
615588
})
616589
}

0 commit comments

Comments
 (0)