Skip to content

Commit

Permalink
Make vcr tester Run and RunParallel use options struct (GoogleCloudPl…
Browse files Browse the repository at this point in the history
…atform#11628)

Co-authored-by: Stephen Lewis (Burrows) <stephen.r.burrows@gmail.com>
  • Loading branch information
2 people authored and Mehul3217 committed Sep 5, 2024
1 parent dbad5ae commit af8d9e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .ci/magician/cmd/test_terraform_vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ func runReplaying(runFullVCR bool, services map[string]struct{}, vt *vcr.Tester)
var replayingErr error
if runFullVCR {
fmt.Println("runReplaying: full VCR tests")
result, replayingErr = vt.Run(vcr.Replaying, provider.Beta, nil)
result, replayingErr = vt.Run(vcr.RunOptions{
Mode: vcr.Replaying,
Version: provider.Beta,
})
} else if len(services) > 0 {
fmt.Printf("runReplaying: %d specific services: %v\n", len(services), services)
for service := range services {
Expand Down
18 changes: 9 additions & 9 deletions .ci/magician/vcr/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ type RunOptions struct {

// Run the vcr tests in the given mode and provider version and return the result.
// This will overwrite any existing logs for the given mode and version.
func (vt *Tester) Run(mode Mode, version provider.Version, testDirs []string) (Result, error) {
logPath, err := vt.getLogPath(mode, version)
func (vt *Tester) Run(opt RunOptions) (Result, error) {
logPath, err := vt.getLogPath(opt.Mode, opt.Version)
if err != nil {
return Result{}, err
}

repoPath, ok := vt.repoPaths[opt.Version]
if !ok {
return Result{}, fmt.Errorf("no repo cloned for version %s in %v", version, vt.repoPaths)
return Result{}, fmt.Errorf("no repo cloned for version %s in %v", opt.Version, vt.repoPaths)
}
if err := vt.rnr.PushDir(repoPath); err != nil {
return Result{}, err
Expand All @@ -176,7 +176,7 @@ func (vt *Tester) Run(mode Mode, version provider.Version, testDirs []string) (R
case Replaying:
cassettePath, ok = vt.cassettePaths[opt.Version]
if !ok {
return Result{}, fmt.Errorf("cassettes not fetched for version %s", version)
return Result{}, fmt.Errorf("cassettes not fetched for version %s", opt.Version)
}
case Recording:
if err := vt.rnr.RemoveAll(cassettePath); err != nil {
Expand Down Expand Up @@ -253,17 +253,17 @@ func (vt *Tester) Run(mode Mode, version provider.Version, testDirs []string) (R
return collectResult(output), testErr
}

func (vt *Tester) RunParallel(mode Mode, version provider.Version, testDirs, tests []string) (Result, error) {
logPath, err := vt.getLogPath(mode, version)
func (vt *Tester) RunParallel(opt RunOptions) (Result, error) {
logPath, err := vt.getLogPath(opt.Mode, opt.Version)
if err != nil {
return Result{}, err
}
if err := vt.rnr.Mkdir(filepath.Join(vt.baseDir, "testlogs", mode.Lower()+"_build")); err != nil {
if err := vt.rnr.Mkdir(filepath.Join(vt.baseDir, "testlogs", opt.Mode.Lower()+"_build")); err != nil {
return Result{}, err
}
repoPath, ok := vt.repoPaths[opt.Version]
if !ok {
return Result{}, fmt.Errorf("no repo cloned for version %s in %v", version, vt.repoPaths)
return Result{}, fmt.Errorf("no repo cloned for version %s in %v", opt.Version, vt.repoPaths)
}
if err := vt.rnr.PushDir(repoPath); err != nil {
return Result{}, err
Expand All @@ -281,7 +281,7 @@ func (vt *Tester) RunParallel(mode Mode, version provider.Version, testDirs, tes
case Replaying:
cassettePath, ok = vt.cassettePaths[opt.Version]
if !ok {
return Result{}, fmt.Errorf("cassettes not fetched for version %s", version)
return Result{}, fmt.Errorf("cassettes not fetched for version %s", opt.Version)
}
case Recording:
if err := vt.rnr.RemoveAll(cassettePath); err != nil {
Expand Down

0 comments on commit af8d9e5

Please sign in to comment.