Skip to content

Commit

Permalink
Switched to emoji for color-based emphasis (GoogleCloudPlatform#11861)
Browse files Browse the repository at this point in the history
  • Loading branch information
melinath authored and BBBmau committed Oct 24, 2024
1 parent 6b9297c commit e355a5b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 77 deletions.
13 changes: 12 additions & 1 deletion .ci/magician/cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,16 @@ func color(color, text string) string {
if color == "" || text == "" {
return text
}
return fmt.Sprintf("$\\textcolor{%s}{\\textsf{%s}}$", color, text)
var emoji string
switch color {
case "red":
emoji = "🔴"
case "yellow":
emoji = "🟡"
case "green":
emoji = "🟢"
default:
return text
}
return fmt.Sprintf("%s %s", emoji, text)
}
16 changes: 14 additions & 2 deletions .ci/magician/cmd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ func TestColor(t *testing.T) {
name: "red",
color: "red",
text: "Test text",
want: "$\\textcolor{red}{\\textsf{Test text}}$",
want: "🔴 Test text",
},
{
name: "yellow",
color: "yellow",
text: "Test text",
want: "🟡 Test text",
},
{
name: "green",
color: "green",
text: "Test text",
want: "$\\textcolor{green}{\\textsf{Test text}}$",
want: "🟢 Test text",
},
{
name: "unsupported color",
color: "mauve",
text: "Test text",
want: "Test text",
},
{
name: "empty color",
Expand Down
6 changes: 3 additions & 3 deletions .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ func runReplaying(runFullVCR bool, services map[string]struct{}, vt *vcr.Tester)

func handlePanics(prNumber, buildID, buildStatusTargetURL, mmCommitSha string, result vcr.Result, mode vcr.Mode, gh GithubClient) (bool, error) {
if len(result.Panics) > 0 {
comment := fmt.Sprintf(`$\textcolor{red}{\textsf{The provider crashed while running the VCR tests in %s mode}}$
$\textcolor{red}{\textsf{Please fix it to complete your PR}}$
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())
comment := color("red", fmt.Sprintf("The provider crashed while running the VCR tests in %s mode\n", mode.Upper()))
comment += fmt.Sprintf(`Please fix it to complete your PR.
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())
if err := gh.PostComment(prNumber, comment); err != nil {
return true, fmt.Errorf("error posting comment: %v", err)
}
Expand Down
115 changes: 44 additions & 71 deletions .ci/magician/cmd/test_terraform_vcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func TestWithoutReplayFailedTests(t *testing.T) {
tests := []struct {
name string
data withoutReplayFailedTests
want string
wantContains []string
}{
{
name: "with replay error",
Expand All @@ -478,29 +478,21 @@ func TestWithoutReplayFailedTests(t *testing.T) {
BuildID: "build-123",
PRNumber: "123",
},
want: strings.Join(
[]string{
"$\\textcolor{red}{\\textsf{Errors occurred during REPLAYING mode. Please fix them to complete your PR.}}$",
"",
"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)",
},
"\n",
),
wantContains: []string{
color("red", "Errors occurred during REPLAYING mode. Please fix them to complete your PR."),
"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)",
},
},
{
name: "without replay error",
data: withoutReplayFailedTests{
BuildID: "build-123",
PRNumber: "123",
},
want: strings.Join(
[]string{
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
"",
"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)",
},
"\n",
),
wantContains: []string{
color("green", "All tests passed!"),
"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)",
},
},
}
for _, tc := range tests {
Expand All @@ -509,8 +501,10 @@ func TestWithoutReplayFailedTests(t *testing.T) {
if err != nil {
t.Fatalf("Failed to format comment: %v", err)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("formatWithoutReplayFailedTests() returned unexpected difference (-want +got):\n%s", diff)
for _, wc := range tc.wantContains {
if !strings.Contains(got, wc) {
t.Errorf("formatWithoutReplayFailedTests() returned %q, which does not contain %q", got, wc)
}
}
})
}
Expand All @@ -520,7 +514,7 @@ func TestRecordReplay(t *testing.T) {
tests := []struct {
name string
data recordReplay
want string
wantContains []string
}{
{
name: "ReplayingAfterRecordingResult has failed tests",
Expand All @@ -538,36 +532,23 @@ func TestRecordReplay(t *testing.T) {
BuildID: "build-123",
PRNumber: "123",
},
want: strings.Join(
[]string{
"$\\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)]",
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
"$\\textcolor{red}{\\textsf{Tests failed when rerunning REPLAYING mode:}}$",
"`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)]",
"`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)]",
"",
"",
"Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.",
"",
"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.",
"",
"",
"---",
"",
"",
"$\\textcolor{red}{\\textsf{Tests failed during RECORDING mode:}}$",
"`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)]",
"`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)]",
"",
"$\\textcolor{red}{\\textsf{Several tests got terminated during RECORDING mode.}}$",
"$\\textcolor{red}{\\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$",
"",
"",
"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",
},
"\n",
),
wantContains: []string{
color("green", "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)]",
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
color("red", "Tests failed when rerunning REPLAYING mode:"),
"`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)]",
"`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)]",
"Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.",
"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.",
color("red", "Tests failed during RECORDING mode:"),
"`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)]",
"`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)]",
color("red", "Several tests got terminated during RECORDING mode."),
"Errors occurred during RECORDING mode. Please fix them to complete your PR.",
"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",
},
},
{
name: "ReplayingAfterRecordingResult does not have failed tests",
Expand All @@ -582,25 +563,15 @@ func TestRecordReplay(t *testing.T) {
BuildID: "build-123",
PRNumber: "123",
},
want: strings.Join(
[]string{
"$\\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)]",
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
"",
"$\\textcolor{green}{\\textsf{No issues found for passed tests after REPLAYING rerun.}}$",
"",
"---",
"",
"",
"",
"",
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
"",
"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",
},
"\n",
),
wantContains: []string{
color("green", "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)]",
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/b.log)]",
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-123/artifacts/build-123/recording/c.log)]",
color("green", "No issues found for passed tests after REPLAYING rerun."),
color("green", "All tests passed!"),
"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",
},
},
}
for _, tc := range tests {
Expand All @@ -609,8 +580,10 @@ func TestRecordReplay(t *testing.T) {
if err != nil {
t.Fatalf("Failed to format comment: %v", err)
}
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("formatRecordReplay() returned unexpected difference (-want +got):\n%s", diff)
for _, wc := range tc.wantContains {
if !strings.Contains(got, wc) {
t.Errorf("formatRecordReplay() returned %q, which does not contain %q", got, wc)
}
}
})
}
Expand Down

0 comments on commit e355a5b

Please sign in to comment.