-
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 to output the HTML report
- Loading branch information
1 parent
1fd4586
commit 15622d8
Showing
19 changed files
with
323 additions
and
87 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ collector-coverage.out | |
dist/ | ||
.vscode/launch.json | ||
sample.yaml | ||
.DS_Store |
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
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,33 @@ | ||
<!DOCTYPE> | ||
<html lang="zh"> | ||
<head> | ||
<title>API Testing Report</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style type="text/css"> | ||
[leading-7=""] { | ||
line-height: 1.75rem; | ||
} | ||
.text-center, [text-center=""] { | ||
text-align: center; | ||
} | ||
footer { | ||
position: fixed; | ||
bottom: 0; | ||
width: 100%; | ||
height: 60px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<table> | ||
<caption>API Testing Report</caption> | ||
<tr><th>API</th><th>Average</th><th>Max</th><th>Min</th><th>Count</th><th>Error</th></tr> | ||
{{- range $val := .}} | ||
<tr><td>{{$val.API}}</td><td>{{$val.Average}}</td><td>{{$val.Max}}</td><td>{{$val.Min}}</td><td>{{$val.Count}}</td><td>{{$val.Error}}</td></tr> | ||
{{- end}} | ||
</table> | ||
<footer text-center="" leading-7=""> | ||
<p text-sm=""><a href="https://github.com/LinuxSuRen/api-testing" target="_blank" rel="noopener">Powered by API Testing</a></p> | ||
</footer> | ||
</body> | ||
</html> |
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
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,31 @@ | ||
<!DOCTYPE> | ||
<html lang="zh"> | ||
<head> | ||
<title>API Testing Report</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<style type="text/css"> | ||
[leading-7=""] { | ||
line-height: 1.75rem; | ||
} | ||
.text-center, [text-center=""] { | ||
text-align: center; | ||
} | ||
footer { | ||
position: fixed; | ||
bottom: 0; | ||
width: 100%; | ||
height: 60px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<table> | ||
<caption>API Testing Report</caption> | ||
<tr><th>API</th><th>Average</th><th>Max</th><th>Min</th><th>Count</th><th>Error</th></tr> | ||
<tr><td>/foo</td><td>3ns</td><td>3ns</td><td>3ns</td><td>1</td><td>0</td></tr> | ||
</table> | ||
<footer text-center="" leading-7=""> | ||
<p text-sm=""><a href="https://github.com/LinuxSuRen/api-testing" target="_blank" rel="noopener">Powered by API Testing</a></p> | ||
</footer> | ||
</body> | ||
</html> |
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,25 @@ | ||
package runner | ||
|
||
import ( | ||
_ "embed" | ||
"io" | ||
|
||
"github.com/linuxsuren/api-testing/pkg/render" | ||
) | ||
|
||
type htmlResultWriter struct { | ||
writer io.Writer | ||
} | ||
|
||
// NewHTMLResultWriter creates a new htmlResultWriter | ||
func NewHTMLResultWriter(writer io.Writer) ReportResultWriter { | ||
return &htmlResultWriter{writer: writer} | ||
} | ||
|
||
// Output writes the HTML base report to target writer | ||
func (w *htmlResultWriter) Output(result []ReportResult) (err error) { | ||
return render.RenderThenPrint("html-report", htmlReport, result, w.writer) | ||
} | ||
|
||
//go:embed data/html.html | ||
var htmlReport string |
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,43 @@ | ||
package runner_test | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
_ "embed" | ||
|
||
"github.com/linuxsuren/api-testing/pkg/runner" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHTMLResultWriter(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
buf *bytes.Buffer | ||
results []runner.ReportResult | ||
expect string | ||
}{{ | ||
name: "simple", | ||
buf: new(bytes.Buffer), | ||
results: []runner.ReportResult{{ | ||
API: "/foo", | ||
Max: 3, | ||
Min: 3, | ||
Average: 3, | ||
Error: 0, | ||
Count: 1, | ||
}}, | ||
expect: htmlReportExpect, | ||
}} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
w := runner.NewHTMLResultWriter(tt.buf) | ||
err := w.Output(tt.results) | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.expect, tt.buf.String()) | ||
}) | ||
} | ||
} | ||
|
||
//go:embed testdata/report.html | ||
var htmlReportExpect string |
Oops, something went wrong.