-
Notifications
You must be signed in to change notification settings - Fork 0
/
venom_output_html.go
37 lines (30 loc) · 775 Bytes
/
venom_output_html.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package venom
import (
"bytes"
_ "embed"
"encoding/json"
"text/template"
"github.com/pkg/errors"
)
//go:embed venom_output.html
var templateHTML string
type TestsHTML struct {
Tests Tests `json:"tests"`
JSONValue string `json:"jsonValue"`
}
func outputHTML(testsResult *Tests) ([]byte, error) {
var buf bytes.Buffer
testJSON, err := json.MarshalIndent(testsResult, "", " ")
if err != nil {
return nil, errors.Wrap(err, "unable to make json value")
}
testsHTML := TestsHTML{
Tests: *testsResult,
JSONValue: string(testJSON),
}
tmpl := template.Must(template.New("reportHTML").Parse(templateHTML))
if err := tmpl.Execute(&buf, testsHTML); err != nil {
return nil, errors.Wrap(err, "unable to make template")
}
return buf.Bytes(), nil
}