Skip to content

Commit

Permalink
Prevent duplicate entries in vcr results (GoogleCloudPlatform#10068)
Browse files Browse the repository at this point in the history
* Prevent duplicate entries in vcr results

* Create empty map

* Only collect result from current test
  • Loading branch information
trodge authored and balanaguharsha committed May 2, 2024
1 parent 0b39130 commit 407b7d9
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions .ci/magician/vcr/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ func (vt *Tester) Run(mode Mode, version provider.Version, testDirs []string) (*
logFileName := filepath.Join(vt.baseDir, "testlogs", fmt.Sprintf("%s_test.log", mode.Lower()))
// Write output (or error) to test log.
// Append to existing log file.
previousLog, _ := vt.rnr.ReadFile(logFileName)
if previousLog != "" {
output = previousLog + "\n" + output
allOutput, _ := vt.rnr.ReadFile(logFileName)
if allOutput != "" {
allOutput += "\n"
}
if err := vt.rnr.WriteFile(logFileName, output); err != nil {
return nil, fmt.Errorf("error writing log: %v, test output: %v", err, output)
allOutput += output
if err := vt.rnr.WriteFile(logFileName, allOutput); err != nil {
return nil, fmt.Errorf("error writing log: %v, test output: %v", err, allOutput)
}
return collectResult(output), testErr
}
Expand Down Expand Up @@ -319,7 +320,7 @@ func (vt *Tester) runInParallel(mode Mode, version provider.Version, testDir, te
"-parallel",
"1",
"-v",
"-run=" + test,
"-run=" + test + "$",
"-timeout",
replayingTimeout,
"-ldflags=-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc",
Expand Down Expand Up @@ -473,19 +474,26 @@ func (vt *Tester) printLogs(logPath string) {

func collectResult(output string) *Result {
matches := testResultsExpression.FindAllStringSubmatch(output, -1)
results := make(map[string][]string, 4)
resultSets := make(map[string]map[string]struct{}, 4)
for _, submatches := range matches {
if len(submatches) != 3 {
fmt.Printf("Warning: unexpected regex match found in test output: %v", submatches)
continue
}
results[submatches[1]] = append(results[submatches[1]], submatches[2])
if _, ok := resultSets[submatches[1]]; !ok {
resultSets[submatches[1]] = make(map[string]struct{})
}
resultSets[submatches[1]][submatches[2]] = struct{}{}
}
results := make(map[string][]string, 4)
results["PANIC"] = testPanicExpression.FindAllString(output, -1)
sort.Strings(results["FAIL"])
sort.Strings(results["PASS"])
sort.Strings(results["SKIP"])
sort.Strings(results["PANIC"])
for _, kind := range []string{"FAIL", "PASS", "SKIP"} {
for test := range resultSets[kind] {
results[kind] = append(results[kind], test)
}
sort.Strings(results[kind])
}
return &Result{
FailedTests: results["FAIL"],
PassedTests: results["PASS"],
Expand Down

0 comments on commit 407b7d9

Please sign in to comment.