-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support output the test report (#17)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
- Loading branch information
1 parent
4a4554d
commit 078d4c8
Showing
11 changed files
with
408 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Print the code of lines: | ||
|
||
```shell | ||
git ls-files | xargs cloc | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ build: | |
copy: build | ||
sudo cp bin/atest /usr/local/bin/ | ||
test: | ||
go test ./... | ||
go test ./... -cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
| API | Average | Max | Min | Count | Error | | ||
|---|---|---|---|---|---| | ||
{{- range $val := .}} | ||
| {{$val.API}} | {{$val.Average}} | {{$val.Max}} | {{$val.Min}} | {{$val.Count}} | {{$val.Error}} | | ||
{{- end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package runner | ||
|
||
type discardTestReporter struct { | ||
} | ||
|
||
// NewDiscardTestReporter creates a test reporter which discard everything | ||
func NewDiscardTestReporter() TestReporter { | ||
return &discardTestReporter{} | ||
} | ||
|
||
func (r *discardTestReporter) PutRecord(*ReportRecord) {} | ||
func (r *discardTestReporter) GetAllRecords() []*ReportRecord { | ||
return nil | ||
} | ||
func (r *discardTestReporter) ExportAllReportResults() (ReportResultSlice, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package runner_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/linuxsuren/api-testing/pkg/runner" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDiscardTestReporter(t *testing.T) { | ||
reporter := runner.NewDiscardTestReporter() | ||
assert.NotNil(t, reporter) | ||
assert.Nil(t, reporter.GetAllRecords()) | ||
|
||
result, err := reporter.ExportAllReportResults() | ||
assert.Nil(t, result) | ||
assert.Nil(t, err) | ||
|
||
reporter.PutRecord(&runner.ReportRecord{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package runner | ||
|
||
import ( | ||
"sort" | ||
"time" | ||
) | ||
|
||
type memoryTestReporter struct { | ||
records []*ReportRecord | ||
} | ||
|
||
// NewmemoryTestReporter creates a memory based test reporter | ||
func NewmemoryTestReporter() TestReporter { | ||
return &memoryTestReporter{ | ||
records: []*ReportRecord{}, | ||
} | ||
} | ||
|
||
type ReportResultWithTotal struct { | ||
ReportResult | ||
Total time.Duration | ||
} | ||
|
||
func (r *memoryTestReporter) PutRecord(record *ReportRecord) { | ||
r.records = append(r.records, record) | ||
} | ||
func (r *memoryTestReporter) GetAllRecords() []*ReportRecord { | ||
return r.records | ||
} | ||
func (r *memoryTestReporter) ExportAllReportResults() (result ReportResultSlice, err error) { | ||
resultWithTotal := map[string]*ReportResultWithTotal{} | ||
for _, record := range r.records { | ||
api := record.Method + " " + record.API | ||
duration := record.Duration() | ||
|
||
if item, ok := resultWithTotal[api]; ok { | ||
if item.Max < duration { | ||
item.Max = duration | ||
} | ||
|
||
if item.Min > duration { | ||
item.Min = duration | ||
} | ||
item.Error += record.ErrorCount() | ||
item.Total += duration | ||
item.Count += 1 | ||
} else { | ||
resultWithTotal[api] = &ReportResultWithTotal{ | ||
ReportResult: ReportResult{ | ||
API: api, | ||
Count: 1, | ||
Max: duration, | ||
Min: duration, | ||
Error: record.ErrorCount(), | ||
}, | ||
Total: duration, | ||
} | ||
} | ||
} | ||
|
||
for _, r := range resultWithTotal { | ||
r.Average = r.Total / time.Duration(r.Count) | ||
result = append(result, r.ReportResult) | ||
} | ||
|
||
sort.Sort(result) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.