Skip to content

Commit c9653ef

Browse files
authored
VCR temporary workaround for GKE issue (#15452)
1 parent 441c4e0 commit c9653ef

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

.ci/magician/cmd/test_terraform_vcr.go

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -449,16 +450,65 @@ func modifiedPackages(changedFiles []string, version provider.Version) (map[stri
449450
return services, runFullVCR
450451
}
451452

453+
func allSubFolders(root string) (map[string]struct{}, error) {
454+
subfolders := make(map[string]struct{})
455+
entries, err := os.ReadDir(root)
456+
if err != nil {
457+
return nil, fmt.Errorf("failed to read directory '%s': %w", root, err)
458+
}
459+
460+
for _, entry := range entries {
461+
if entry.IsDir() {
462+
subfolders[entry.Name()] = struct{}{}
463+
}
464+
}
465+
return subfolders, nil
466+
}
467+
452468
func runReplaying(runFullVCR bool, version provider.Version, services map[string]struct{}, vt *vcr.Tester) (vcr.Result, []string, error) {
453469
result := vcr.Result{}
454470
var testDirs []string
455471
var replayingErr error
456472
if runFullVCR {
457473
fmt.Println("runReplaying: full VCR tests")
474+
// result, replayingErr = vt.Run(vcr.RunOptions{
475+
// Mode: vcr.Replaying,
476+
// Version: version,
477+
// })
478+
479+
// temporary workaround
480+
serviceRoot := filepath.Join(vt.GetRepoPath(version), version.ProviderName(), "services")
481+
allServies, err := allSubFolders(serviceRoot)
482+
if err != nil {
483+
return result, testDirs, err
484+
}
485+
486+
var gkePath string
487+
var otherPaths []string
488+
for service := range allServies {
489+
servicePath := "./" + filepath.Join(version.ProviderName(), "services", service)
490+
if service == "container" {
491+
gkePath = servicePath
492+
continue
493+
}
494+
otherPaths = append(otherPaths, servicePath)
495+
}
458496
result, replayingErr = vt.Run(vcr.RunOptions{
459-
Mode: vcr.Replaying,
460-
Version: version,
497+
Mode: vcr.Replaying,
498+
Version: version,
499+
TestDirs: otherPaths,
500+
})
501+
// run gke replaying tests separately
502+
gkeResult, gkeReplayingErr := vt.Run(vcr.RunOptions{
503+
Mode: vcr.Replaying,
504+
Version: version,
505+
TestDirs: []string{gkePath},
461506
})
507+
replayingErr = errors.Join(replayingErr, gkeReplayingErr)
508+
result.PassedTests = append(result.PassedTests, gkeResult.PassedTests...)
509+
result.SkippedTests = append(result.SkippedTests, gkeResult.SkippedTests...)
510+
result.FailedTests = append(result.FailedTests, gkeResult.FailedTests...)
511+
result.Panics = append(result.Panics, gkeResult.Panics...)
462512
} else if len(services) > 0 {
463513
fmt.Printf("runReplaying: %d specific services: %v\n", len(services), services)
464514
for service := range services {
@@ -470,9 +520,7 @@ func runReplaying(runFullVCR bool, version provider.Version, services map[string
470520
Version: version,
471521
TestDirs: []string{servicePath},
472522
})
473-
if serviceReplayingErr != nil {
474-
replayingErr = serviceReplayingErr
475-
}
523+
replayingErr = errors.Join(replayingErr, serviceReplayingErr)
476524
result.PassedTests = append(result.PassedTests, serviceResult.PassedTests...)
477525
result.SkippedTests = append(result.SkippedTests, serviceResult.SkippedTests...)
478526
result.FailedTests = append(result.FailedTests, serviceResult.FailedTests...)

.ci/magician/vcr/tester.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func (vt *Tester) SetRepoPath(version provider.Version, repoPath string) {
140140
vt.repoPaths[version] = repoPath
141141
}
142142

143+
func (vt *Tester) GetRepoPath(version provider.Version) string {
144+
return vt.repoPaths[version]
145+
}
146+
143147
// Fetch the cassettes for the current version if not already fetched.
144148
// Should be run from the base dir.
145149
func (vt *Tester) FetchCassettes(version provider.Version, baseBranch, head string) error {

0 commit comments

Comments
 (0)