Skip to content

Commit

Permalink
Fix issues found in review
Browse files Browse the repository at this point in the history
  • Loading branch information
trodge committed Sep 11, 2024
1 parent f02873e commit 277b088
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .ci/magician/cmd/check_cassettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var checkCassettesCmd = &cobra.Command{

ctlr := source.NewController(env["GOPATH"], "modular-magician", githubToken, rnr)

vt, err := vcr.NewTester(env, "ci-vcr-logs", "ci-vcr-cassettes", rnr)
vt, err := vcr.NewTester(env, "vcr-check-cassettes", "ci-vcr-cassettes", rnr)
if err != nil {
return fmt.Errorf("error creating VCR tester: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var testTerraformVCRCmd = &cobra.Command{
}
ctlr := source.NewController(env["GOPATH"], "modular-magician", env["GITHUB_TOKEN_DOWNSTREAMS"], rnr)

vt, err := vcr.NewTester(env, "ci-vcr-logs", "ci-vcr-cassetes", rnr)
vt, err := vcr.NewTester(env, "ci-vcr-logs", "vcr-check-cassettes", rnr)
if err != nil {
return fmt.Errorf("error creating VCR tester: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion .ci/magician/cmd/vcr_cassette_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var vcrCassetteUpdateCmd = &cobra.Command{
}
ctlr := source.NewController(env["GOPATH"], "hashicorp", env["GITHUB_TOKEN_CLASSIC"], rnr)

vt, err := vcr.NewTester(env, "ci-vcr-logs", "ci-vcr-cassettes", rnr)
vt, err := vcr.NewTester(env, "", "ci-vcr-cassettes", rnr)
if err != nil {
return fmt.Errorf("error creating VCR tester: %w", err)
}
Expand Down
12 changes: 8 additions & 4 deletions .ci/magician/exec/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ func (ar *Runner) ReadFile(name string) (string, error) {
}

func (ar *Runner) AppendFile(name, data string) error {
existing, err := ar.ReadFile(name)
if err != nil && !os.IsNotExist(err) {
return err
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 ar.WriteFile(name, existing+data)
return nil
}

// Run the given command with the given args and env, return output and error if any
Expand Down
16 changes: 6 additions & 10 deletions .ci/magician/vcr/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,30 +138,26 @@ func (vt *Tester) FetchCassettes(version provider.Version, baseBranch, head stri
}
cassettePath := filepath.Join(vt.baseDir, "cassettes", version.String())
vt.rnr.Mkdir(cassettePath)
fetchErrors := make([]error, 0, 3)
if baseBranch != "FEATURE-BRANCH-major-release-6.0.0" {
// pull main cassettes (major release uses branch specific casssettes as primary ones)
bucketPath := fmt.Sprintf("gs://%s/%sfixtures/*", vt.cassetteBucket, version.BucketPath())
bucketPath := fmt.Sprintf("gs://ci-vcr-cassettes/%sfixtures/*", version.BucketPath())
if err := vt.fetchBucketPath(bucketPath, cassettePath); err != nil {
fetchErrors = append(fetchErrors, fmt.Errorf("error fetching bucket path %s: %v", bucketPath, err))
fmt.Println("Error fetching cassettes: ", err)
}
}
if baseBranch != "main" {
bucketPath := fmt.Sprintf("gs://%s/%srefs/branches/%s/fixtures/*", vt.cassetteBucket, version.BucketPath(), baseBranch)
bucketPath := fmt.Sprintf("gs://ci-vcr-cassettes/%srefs/branches/%s/fixtures/*", version.BucketPath(), baseBranch)
if err := vt.fetchBucketPath(bucketPath, cassettePath); err != nil {
fetchErrors = append(fetchErrors, fmt.Errorf("error fetching bucket path %s: %v", bucketPath, err))
fmt.Println("Error fetching cassettes: ", err)
}
}
if head != "" {
bucketPath := fmt.Sprintf("gs://%s/%srefs/heads/%s/fixtures/*", vt.cassetteBucket, version.BucketPath(), head)
bucketPath := fmt.Sprintf("gs://ci-vcr-cassettes/%srefs/heads/%s/fixtures/*", version.BucketPath(), head)
if err := vt.fetchBucketPath(bucketPath, cassettePath); err != nil {
fetchErrors = append(fetchErrors, fmt.Errorf("error fetching bucket path %s: %v", bucketPath, err))
fmt.Println("Error fetching cassettes: ", err)
}
}
vt.cassettePaths[version] = cassettePath
if len(fetchErrors) > 0 {
return fmt.Errorf("errors fetching cassettes: %v", fetchErrors)
}
return nil
}

Expand Down

0 comments on commit 277b088

Please sign in to comment.