|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "log" |
| 5 | + |
| 6 | + "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports" |
| 7 | + "github.com/spf13/cobra" |
| 8 | +) |
| 9 | + |
| 10 | +var AggregateResultsCmd = &cobra.Command{ |
| 11 | + Use: "aggregate-results", |
| 12 | + Short: "Aggregate test results and optionally filter failed tests based on a threshold", |
| 13 | + Run: func(cmd *cobra.Command, args []string) { |
| 14 | + resultsFolderPath, _ := cmd.Flags().GetString("results-path") |
| 15 | + outputResultsPath, _ := cmd.Flags().GetString("output-results") |
| 16 | + outputLogsPath, _ := cmd.Flags().GetString("output-logs") |
| 17 | + threshold, _ := cmd.Flags().GetFloat64("threshold") |
| 18 | + minPassRatio, _ := cmd.Flags().GetFloat64("min-pass-ratio") |
| 19 | + filterFailed, _ := cmd.Flags().GetBool("filter-failed") |
| 20 | + |
| 21 | + // Aggregate all test results |
| 22 | + allResults, err := reports.AggregateTestResults(resultsFolderPath) |
| 23 | + if err != nil { |
| 24 | + log.Fatalf("Error aggregating results: %v", err) |
| 25 | + } |
| 26 | + |
| 27 | + var resultsToSave []reports.TestResult |
| 28 | + |
| 29 | + if filterFailed { |
| 30 | + // Filter to only include failed tests based on threshold and minPassRatio |
| 31 | + for _, result := range allResults { |
| 32 | + if result.PassRatio < threshold && result.PassRatio > minPassRatio && !result.Skipped { |
| 33 | + resultsToSave = append(resultsToSave, result) |
| 34 | + } |
| 35 | + } |
| 36 | + } else { |
| 37 | + resultsToSave = allResults |
| 38 | + } |
| 39 | + |
| 40 | + // Output results to JSON files |
| 41 | + if len(resultsToSave) > 0 { |
| 42 | + reports.SaveFilteredResultsAndLogs(outputResultsPath, outputLogsPath, resultsToSave) |
| 43 | + } |
| 44 | + }, |
| 45 | +} |
| 46 | + |
| 47 | +func init() { |
| 48 | + AggregateResultsCmd.Flags().String("results-path", "", "Path to the folder containing JSON test result files") |
| 49 | + AggregateResultsCmd.Flags().String("output-results", "./results.json", "Path to output the aggregated or filtered test results in JSON format") |
| 50 | + AggregateResultsCmd.Flags().String("output-logs", "", "Path to output the filtered test logs in JSON format") |
| 51 | + AggregateResultsCmd.Flags().Float64("threshold", 0.8, "Threshold for considering a test as failed (used with --filter-failed)") |
| 52 | + AggregateResultsCmd.Flags().Float64("min-pass-ratio", 0.001, "Minimum pass ratio for considering a test as flaky (used with --filter-failed)") |
| 53 | + AggregateResultsCmd.Flags().Bool("filter-failed", false, "If true, filter and output only failed tests based on the threshold") |
| 54 | +} |
0 commit comments