Skip to content

Commit

Permalink
Trivial magician changes (GoogleCloudPlatform#11712)
Browse files Browse the repository at this point in the history
  • Loading branch information
trodge authored Sep 16, 2024
1 parent bd193c6 commit 51c8482
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .ci/magician/cmd/generate_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
)

var (
//go:embed DIFF_COMMENT.md
//go:embed templates/DIFF_COMMENT.md.tmpl
diffComment string
)

Expand Down
1 change: 1 addition & 0 deletions .ci/magician/cmd/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ExecRunner interface {
PushDir(path string) error
PopDir() error
WriteFile(name, data string) error
AppendFile(name, data string) error // Not used (yet).
Run(name string, args []string, env map[string]string) (string, error)
MustRun(name string, args []string, env map[string]string) string
}
4 changes: 4 additions & 0 deletions .ci/magician/cmd/mock_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (mr *mockRunner) WriteFile(name, data string) error {
return nil
}

func (mr *mockRunner) AppendFile(name, data string) error {
return nil
}

func (mr *mockRunner) Copy(src, dest string) error {
mr.calledMethods["Copy"] = append(mr.calledMethods["Copy"], ParameterList{src, dest})
return nil
Expand Down
6 changes: 3 additions & 3 deletions .ci/magician/cmd/scheduled_pr_reminders.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ var (
// used for flags
dryRun bool

//go:embed SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl
//go:embed templates/SCHEDULED_PR_WAITING_FOR_CONTRIBUTOR.md.tmpl
waitingForContributorTemplate string

//go:embed SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl
//go:embed templates/SCHEDULED_PR_WAITING_FOR_MERGE.md.tmpl
waitingForMergeTemplate string

//go:embed SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl
//go:embed templates/SCHEDULED_PR_WAITING_FOR_REVIEW.md.tmpl
waitingForReviewTemplate string
)

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
)

var (
//go:embed test_terraform_vcr_test_analytics.tmpl
//go:embed templates/vcr/test_analytics.tmpl
testsAnalyticsTmplText string
//go:embed test_terraform_vcr_non_exercised_tests.tmpl
//go:embed templates/vcr/non_exercised_tests.tmpl
nonExercisedTestsTmplText string
//go:embed test_terraform_vcr_with_replay_failed_tests.tmpl
//go:embed templates/vcr/with_replay_failed_tests.tmpl
withReplayFailedTestsTmplText string
//go:embed test_terraform_vcr_without_replay_failed_tests.tmpl
//go:embed templates/vcr/without_replay_failed_tests.tmpl
withoutReplayFailedTestsTmplText string
//go:embed test_terraform_vcr_record_replay.tmpl
//go:embed templates/vcr/record_replay.tmpl
recordReplayTmplText string
)

Expand Down
36 changes: 18 additions & 18 deletions .ci/magician/cmd/test_terraform_vcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ func TestWithoutReplayFailedTests(t *testing.T) {
data: withoutReplayFailedTests{
ReplayingErr: fmt.Errorf("some error"),
BuildID: "build-123",
PRNumber: "pr-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-pr-123/artifacts/build-123/build-log/replaying_test.log)",
"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",
),
Expand All @@ -491,13 +491,13 @@ func TestWithoutReplayFailedTests(t *testing.T) {
name: "without replay error",
data: withoutReplayFailedTests{
BuildID: "build-123",
PRNumber: "pr-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-pr-123/artifacts/build-123/build-log/replaying_test.log)",
"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",
),
Expand Down Expand Up @@ -536,16 +536,16 @@ func TestRecordReplay(t *testing.T) {
HasTerminatedTests: true,
RecordingErr: fmt.Errorf("some error"),
BuildID: "build-123",
PRNumber: "pr-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-pr-123/artifacts/build-123/recording/a.log)]",
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/b.log)]",
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/c.log)]",
"$\\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-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)]",
"`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)]",
"`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.",
Expand All @@ -557,14 +557,14 @@ func TestRecordReplay(t *testing.T) {
"",
"",
"$\\textcolor{red}{\\textsf{Tests failed during RECORDING mode:}}$",
"`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)]",
"`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)]",
"`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-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",
"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",
),
Expand All @@ -580,13 +580,13 @@ func TestRecordReplay(t *testing.T) {
},
AllRecordingPassed: true,
BuildID: "build-123",
PRNumber: "pr-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-pr-123/artifacts/build-123/recording/a.log)]",
"`b`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/b.log)]",
"`c`[[Debug log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-pr-123/artifacts/build-123/recording/c.log)]",
"$\\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.}}$",
"",
Expand All @@ -597,7 +597,7 @@ func TestRecordReplay(t *testing.T) {
"",
"$\\textcolor{green}{\\textsf{All tests passed!}}$",
"",
"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",
"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",
),
Expand Down
4 changes: 2 additions & 2 deletions .ci/magician/cmd/vcr_cassette_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ var vcuEnvironmentVariables = [...]string{
}

var (
//go:embed vcr_cassettes_update_replaying.tmpl
//go:embed templates/vcr/vcr_cassettes_update_replaying.tmpl
replayingTmplText string
//go:embed vcr_cassettes_update_recording.tmpl
//go:embed templates/vcr/vcr_cassettes_update_recording.tmpl
recordingTmplText string
)

Expand Down
13 changes: 13 additions & 0 deletions .ci/magician/exec/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ func (ar *Runner) ReadFile(name string) (string, error) {
return string(data), nil
}

// Note: This is not used yet.
func (ar *Runner) AppendFile(name, data string) error {
f, err := os.OpenFile(ar.abs(name), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("error opening file %s: %v", name, err)
}
defer f.Close()
if _, err := f.Write([]byte(data)); err != nil {
return fmt.Errorf("error writing to file %s: %v", name, err)
}
return nil
}

// Run the given command with the given args and env, return output and error if any
func (ar *Runner) Run(name string, args []string, env map[string]string) (string, error) {
cmd := exec.Command(name, args...)
Expand Down

0 comments on commit 51c8482

Please sign in to comment.