Skip to content

Commit d90596d

Browse files
committed
fix interfaces
1 parent c56cbd7 commit d90596d

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

wasp/benchspy/report.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (b *StandardReport) Load() error {
2424
return b.LocalStorage.Load(b.TestName, b.CommitOrTag, b)
2525
}
2626

27-
func (b *StandardReport) Fetch(ctx context.Context) error {
27+
func (b *StandardReport) FetchData(ctx context.Context) error {
2828
basicErr := b.BasicData.Validate()
2929
if basicErr != nil {
3030
return basicErr
@@ -60,18 +60,24 @@ func (b *StandardReport) Fetch(ctx context.Context) error {
6060
return nil
6161
}
6262

63-
func (b *StandardReport) IsComparable(otherReport StandardReport) error {
64-
basicErr := b.BasicData.IsComparable(otherReport.BasicData)
63+
func (b *StandardReport) IsComparable(otherReport Reporter) error {
64+
if _, ok := otherReport.(*StandardReport); !ok {
65+
return fmt.Errorf("expected type %s, got %T", "*StandardReport", otherReport)
66+
}
67+
68+
asStandardReport := otherReport.(*StandardReport)
69+
70+
basicErr := b.BasicData.IsComparable(asStandardReport.BasicData)
6571
if basicErr != nil {
6672
return basicErr
6773
}
6874

69-
if resourceErr := b.CompareResources(&otherReport.ResourceReporter); resourceErr != nil {
75+
if resourceErr := b.CompareResources(&asStandardReport.ResourceReporter); resourceErr != nil {
7076
return resourceErr
7177
}
7278

7379
for i, queryExecutor := range b.QueryExecutors {
74-
queryErr := queryExecutor.IsComparable(otherReport.QueryExecutors[i])
80+
queryErr := queryExecutor.IsComparable(asStandardReport.QueryExecutors[i])
7581
if queryErr != nil {
7682
return queryErr
7783
}

wasp/benchspy/types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@ type Storer interface {
1212
Load() error
1313
}
1414

15-
type Fetcher interface {
15+
type DataFetcher interface {
1616
// Fetch populates the report with the data from the test
17-
Fetch() error
17+
FetchData(ctx context.Context) error
1818
}
1919

2020
type Comparator interface {
2121
// IsComparable checks whether both reports can be compared (e.g. test config is the same, app's resources are the same, queries or metrics used are the same, etc.), and an error if any difference is found
2222
IsComparable(otherReport Reporter) error
2323
}
2424

25+
type ResourceFetcher interface {
26+
// FetchResources fetches the resources used by the AUT (e.g. CPU, memory, etc.)
27+
FetchResources(ctx context.Context) error
28+
}
29+
2530
type Reporter interface {
2631
Storer
27-
Fetcher
32+
DataFetcher
33+
ResourceFetcher
2834
Comparator
2935
}
3036

wasp/benchspy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestBenchSpyWithLokiQuery(t *testing.T) {
6666
fetchCtx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
6767
defer cancelFn()
6868

69-
fetchErr := currentReport.Fetch(fetchCtx)
69+
fetchErr := currentReport.FetchData(fetchCtx)
7070
require.NoError(t, fetchErr, "failed to fetch current report")
7171

7272
// path, storeErr := currentReport.Store()
@@ -84,7 +84,7 @@ func TestBenchSpyWithLokiQuery(t *testing.T) {
8484
loadErr := previousReport.Load()
8585
require.NoError(t, loadErr, "failed to load previous report")
8686

87-
isComparableErrs := previousReport.IsComparable(currentReport)
87+
isComparableErrs := previousReport.IsComparable(&currentReport)
8888
require.Empty(t, isComparableErrs, "reports were not comparable", isComparableErrs)
8989
require.NotEmpty(t, currentReport.QueryExecutors[0].Results()["vu_over_time"], "vu_over_time results were missing from current report")
9090
require.NotEmpty(t, previousReport.QueryExecutors[0].Results()["vu_over_time"], "vu_over_time results were missing from current report")
@@ -169,7 +169,7 @@ func TestBenchSpyWithTwoLokiQueries(t *testing.T) {
169169
fetchCtx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
170170
defer cancelFn()
171171

172-
fetchErr := currentReport.Fetch(fetchCtx)
172+
fetchErr := currentReport.FetchData(fetchCtx)
173173
require.NoError(t, fetchErr, "failed to fetch current report")
174174

175175
// path, storeErr := currentReport.Store()
@@ -187,7 +187,7 @@ func TestBenchSpyWithTwoLokiQueries(t *testing.T) {
187187
loadErr := previousReport.Load()
188188
require.NoError(t, loadErr, "failed to load previous report")
189189

190-
isComparableErrs := previousReport.IsComparable(currentReport)
190+
isComparableErrs := previousReport.IsComparable(&currentReport)
191191
require.Empty(t, isComparableErrs, "reports were not comparable", isComparableErrs)
192192
// vu over time
193193
require.NotEmpty(t, currentReport.QueryExecutors[0].Results()["vu_over_time"], "vu_over_time results were missing from current report")

0 commit comments

Comments
 (0)