Skip to content

Commit 51c8482

Browse files
authored
Trivial magician changes (GoogleCloudPlatform#11712)
1 parent bd193c6 commit 51c8482

19 files changed

+47
-29
lines changed

.ci/magician/cmd/generate_comment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
)
4141

4242
var (
43-
//go:embed DIFF_COMMENT.md
43+
//go:embed templates/DIFF_COMMENT.md.tmpl
4444
diffComment string
4545
)
4646

.ci/magician/cmd/interfaces.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type ExecRunner interface {
4747
PushDir(path string) error
4848
PopDir() error
4949
WriteFile(name, data string) error
50+
AppendFile(name, data string) error // Not used (yet).
5051
Run(name string, args []string, env map[string]string) (string, error)
5152
MustRun(name string, args []string, env map[string]string) string
5253
}

.ci/magician/cmd/mock_runner_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func (mr *mockRunner) WriteFile(name, data string) error {
113113
return nil
114114
}
115115

116+
func (mr *mockRunner) AppendFile(name, data string) error {
117+
return nil
118+
}
119+
116120
func (mr *mockRunner) Copy(src, dest string) error {
117121
mr.calledMethods["Copy"] = append(mr.calledMethods["Copy"], ParameterList{src, dest})
118122
return nil

.ci/magician/cmd/scheduled_pr_reminders.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ var (
3838
// used for flags
3939
dryRun bool
4040

41-
//go:embed SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl
41+
//go:embed templates/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl
4242
waitingForContributorTemplate string
4343

44-
//go:embed SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl
44+
//go:embed templates/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl
4545
waitingForMergeTemplate string
4646

47-
//go:embed SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl
47+
//go:embed templates/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl
4848
waitingForReviewTemplate string
4949
)
5050

.ci/magician/cmd/test_terraform_vcr.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121
)
2222

2323
var (
24-
//go:embed test_terraform_vcr_test_analytics.tmpl
24+
//go:embed templates/vcr/test_analytics.tmpl
2525
testsAnalyticsTmplText string
26-
//go:embed test_terraform_vcr_non_exercised_tests.tmpl
26+
//go:embed templates/vcr/non_exercised_tests.tmpl
2727
nonExercisedTestsTmplText string
28-
//go:embed test_terraform_vcr_with_replay_failed_tests.tmpl
28+
//go:embed templates/vcr/with_replay_failed_tests.tmpl
2929
withReplayFailedTestsTmplText string
30-
//go:embed test_terraform_vcr_without_replay_failed_tests.tmpl
30+
//go:embed templates/vcr/without_replay_failed_tests.tmpl
3131
withoutReplayFailedTestsTmplText string
32-
//go:embed test_terraform_vcr_record_replay.tmpl
32+
//go:embed templates/vcr/record_replay.tmpl
3333
recordReplayTmplText string
3434
)
3535

.ci/magician/cmd/test_terraform_vcr_test.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,13 @@ func TestWithoutReplayFailedTests(t *testing.T) {
476476
data: withoutReplayFailedTests{
477477
ReplayingErr: fmt.Errorf("some error"),
478478
BuildID: "build-123",
479-
PRNumber: "pr-123",
479+
PRNumber: "123",
480480
},
481481
want: strings.Join(
482482
[]string{
483483
"$\\textcolor{red}{\\textsf{Errors occurred during REPLAYING mode. Please fix them to complete your PR.}}$",
484484
"",
485-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/replaying_test.log)",
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)",
486486
},
487487
"\n",
488488
),
@@ -491,13 +491,13 @@ func TestWithoutReplayFailedTests(t *testing.T) {
491491
name: "without replay error",
492492
data: withoutReplayFailedTests{
493493
BuildID: "build-123",
494-
PRNumber: "pr-123",
494+
PRNumber: "123",
495495
},
496496
want: strings.Join(
497497
[]string{
498498
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
499499
"",
500-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/build-log/replaying_test.log)",
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)",
501501
},
502502
"\n",
503503
),
@@ -536,16 +536,16 @@ func TestRecordReplay(t *testing.T) {
536536
HasTerminatedTests: true,
537537
RecordingErr: fmt.Errorf("some error"),
538538
BuildID: "build-123",
539-
PRNumber: "pr-123",
539+
PRNumber: "123",
540540
},
541541
want: strings.Join(
542542
[]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-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-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-pr-123/artifacts/build-123/recording/c.log)]",
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)]",
546546
"$\\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-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-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-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-pr-123/artifacts/build-123/replaying_after_recording/c.log)]",
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)]",
549549
"",
550550
"",
551551
"Tests failed due to non-determinism or randomness when the VCR replayed the response after the HTTP request was made.",
@@ -557,14 +557,14 @@ func TestRecordReplay(t *testing.T) {
557557
"",
558558
"",
559559
"$\\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-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-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-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-pr-123/artifacts/build-123/recording/e.log)]",
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)]",
562562
"",
563563
"$\\textcolor{red}{\\textsf{Several tests got terminated during RECORDING mode.}}$",
564564
"$\\textcolor{red}{\\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$",
565565
"",
566566
"",
567-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-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-pr-123/artifacts/build-123/recording) for each test",
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",
568568
},
569569
"\n",
570570
),
@@ -580,13 +580,13 @@ func TestRecordReplay(t *testing.T) {
580580
},
581581
AllRecordingPassed: true,
582582
BuildID: "build-123",
583-
PRNumber: "pr-123",
583+
PRNumber: "123",
584584
},
585585
want: strings.Join(
586586
[]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-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-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-pr-123/artifacts/build-123/recording/c.log)]",
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)]",
590590
"",
591591
"$\\textcolor{green}{\\textsf{No issues found for passed tests after REPLAYING rerun.}}$",
592592
"",
@@ -597,7 +597,7 @@ func TestRecordReplay(t *testing.T) {
597597
"",
598598
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
599599
"",
600-
"View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-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-pr-123/artifacts/build-123/recording) for each test",
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",
601601
},
602602
"\n",
603603
),

.ci/magician/cmd/vcr_cassette_update.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ var vcuEnvironmentVariables = [...]string{
3939
}
4040

4141
var (
42-
//go:embed vcr_cassettes_update_replaying.tmpl
42+
//go:embed templates/vcr/vcr_cassettes_update_replaying.tmpl
4343
replayingTmplText string
44-
//go:embed vcr_cassettes_update_recording.tmpl
44+
//go:embed templates/vcr/vcr_cassettes_update_recording.tmpl
4545
recordingTmplText string
4646
)
4747

.ci/magician/exec/runner.go

+13
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ func (ar *Runner) ReadFile(name string) (string, error) {
100100
return string(data), nil
101101
}
102102

103+
// Note: This is not used yet.
104+
func (ar *Runner) AppendFile(name, data string) error {
105+
f, err := os.OpenFile(ar.abs(name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
106+
if err != nil {
107+
return fmt.Errorf("error opening file %s: %v", name, err)
108+
}
109+
defer f.Close()
110+
if _, err := f.Write([]byte(data)); err != nil {
111+
return fmt.Errorf("error writing to file %s: %v", name, err)
112+
}
113+
return nil
114+
}
115+
103116
// Run the given command with the given args and env, return output and error if any
104117
func (ar *Runner) Run(name string, args []string, env map[string]string) (string, error) {
105118
cmd := exec.Command(name, args...)

0 commit comments

Comments
 (0)