Skip to content

Commit 9e40f27

Browse files
authored
Makes TestReport Aggregation More Flexible (#1429)
* Makes TestReport aggregation more flexible * Better name * Better printing * Remove markdown only formatting * Markdown optional
1 parent f03577d commit 9e40f27

File tree

8 files changed

+181
-162
lines changed

8 files changed

+181
-162
lines changed

framework/components/clnode/clnode.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"os"
9+
"path/filepath"
10+
"sync"
11+
"text/template"
12+
"time"
13+
814
"github.com/docker/docker/api/types/container"
915
"github.com/docker/go-connections/nat"
1016
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1117
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
1218
tc "github.com/testcontainers/testcontainers-go"
1319
"github.com/testcontainers/testcontainers-go/wait"
14-
"os"
15-
"path/filepath"
16-
"sync"
17-
"text/template"
18-
"time"
1920
)
2021

2122
const (
@@ -114,10 +115,10 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
114115
ctx := context.Background()
115116

116117
passwordPath, err := WriteTmpFile(DefaultPasswordTxt, "password.txt")
117-
apiCredentialsPath, err := WriteTmpFile(DefaultAPICredentials, "apicredentials")
118118
if err != nil {
119119
return nil, err
120120
}
121+
apiCredentialsPath, err := WriteTmpFile(DefaultAPICredentials, "apicredentials")
121122
if err != nil {
122123
return nil, err
123124
}

framework/components/clnode/clnode_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package clnode_test
22

33
import (
4+
"sync"
5+
"testing"
6+
47
"github.com/smartcontractkit/chainlink-testing-framework/framework"
58
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/clnode"
69
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
710
"github.com/stretchr/testify/require"
8-
"sync"
9-
"testing"
1011
)
1112

1213
type testCase struct {

framework/components/clnode/connect_network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package clnode
22

33
import (
44
"fmt"
5+
56
"github.com/google/uuid"
67
"github.com/smartcontractkit/chainlink-testing-framework/framework"
78
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"

framework/components/clnode/default.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Dynamic settings are usually used to connect Docker components together
88

99
const (
1010
DefaultTestKeystorePassword = "thispasswordislongenough"
11-
DefaultPasswordTxt = `T.tLHkcmwePT/p,]sYuntjwHKAsrhm#4eRs4LuKHwvHejWYAC2JP4M8HimwgmbaZ`
11+
DefaultPasswordTxt = `T.tLHkcmwePT/p,]sYuntjwHKAsrhm#4eRs4LuKHwvHejWYAC2JP4M8HimwgmbaZ` //nolint:gosec
1212
DefaultAPICredentials = `[email protected]
1313
fj293fbBnlQ!f9vNs`
1414
DefaultAPIUser = `[email protected]`
15-
DefaultAPIPassword = `fj293fbBnlQ!f9vNs`
15+
DefaultAPIPassword = `fj293fbBnlQ!f9vNs` //nolint:gosec
1616
)
1717

1818
const defaultConfigTmpl = `

tools/flakeguard/cmd/aggregate_results.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package cmd
22

33
import (
4+
"encoding/json"
45
"log"
6+
"os"
7+
"path/filepath"
58

69
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
710
"github.com/spf13/cobra"
@@ -21,7 +24,31 @@ var AggregateResultsCmd = &cobra.Command{
2124
Use: "aggregate-results",
2225
Short: "Aggregate test results and optionally filter failed tests based on a threshold",
2326
RunE: func(cmd *cobra.Command, args []string) error {
24-
allReport, err := reports.AggregateTestResults(resultsFolderPath)
27+
// Read test reports from files
28+
var testReports []*reports.TestReport
29+
err := filepath.Walk(resultsFolderPath, func(path string, info os.FileInfo, err error) error {
30+
if err != nil {
31+
return err
32+
}
33+
if !info.IsDir() && filepath.Ext(path) == ".json" {
34+
// Read file content
35+
data, readErr := os.ReadFile(path)
36+
if readErr != nil {
37+
return readErr
38+
}
39+
var report *reports.TestReport
40+
if jsonErr := json.Unmarshal(data, &report); jsonErr != nil {
41+
return jsonErr
42+
}
43+
testReports = append(testReports, report)
44+
}
45+
return nil
46+
})
47+
if err != nil {
48+
log.Fatalf("Error reading test reports: %v", err)
49+
}
50+
51+
allReport, err := reports.Aggregate(testReports...)
2552
if err != nil {
2653
log.Fatalf("Error aggregating results: %v", err)
2754
}

tools/flakeguard/cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var RunTestsCmd = &cobra.Command{
7171
// Print all failed tests including flaky tests
7272
if printFailedTests {
7373
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n", maxPassRatio)
74-
reports.PrintTests(os.Stdout, testReport.Results, maxPassRatio, false)
74+
reports.PrintResults(os.Stdout, testReport.Results, maxPassRatio, false, false)
7575
}
7676

7777
// Save the test results in JSON format

0 commit comments

Comments
 (0)