Initial commit
This commit is contained in:
56
cmd/junit2md/main.go
Normal file
56
cmd/junit2md/main.go
Normal file
@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/joshdk/go-junit"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
templateFile = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&templateFile, "template", templateFile, "The template file to use")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
files := flag.Args()
|
||||
|
||||
suites, err := junit.IngestFiles(files)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not ingest junit files"))
|
||||
}
|
||||
|
||||
for _, s := range suites {
|
||||
s.Aggregate()
|
||||
}
|
||||
|
||||
templateBox := packr.New("template", "./template")
|
||||
defaultReportTemplate, err := templateBox.FindString("report.md.tmpl")
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not find report template"))
|
||||
}
|
||||
|
||||
tmpl, err := template.New("report").Parse(defaultReportTemplate)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not parse template"))
|
||||
}
|
||||
|
||||
templateData := struct {
|
||||
Suites []junit.Suite
|
||||
}{
|
||||
Suites: suites,
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(os.Stdout, templateData); err != nil {
|
||||
panic(errors.Wrap(err, "could not execute template"))
|
||||
}
|
||||
|
||||
}
|
79
cmd/junit2md/template/report.md.tmpl
Normal file
79
cmd/junit2md/template/report.md.tmpl
Normal file
@ -0,0 +1,79 @@
|
||||
# Test report
|
||||
{{range .Suites}}
|
||||
## {{ .Name }}
|
||||
|
||||
### Overview
|
||||
|
||||
| State | Total |
|
||||
|-------|-------|
|
||||
| Passed | {{ .Totals.Passed }} |
|
||||
| Skipped | {{ .Totals.Skipped }} |
|
||||
| Failed | {{ .Totals.Failed }} |
|
||||
| Error | {{ .Totals.Error }} |
|
||||
|
||||
**Total duration**: {{ .Totals.Duration }}
|
||||
|
||||
### Details
|
||||
|
||||
| Status | Name | Class |
|
||||
|--------|------|-------|
|
||||
{{- range .Tests }}
|
||||
| {{ template "status_icon" .Status }} | `{{ .Name }}` ||
|
||||
{{- end -}}
|
||||
{{- range .Suites }}
|
||||
{{- $suite := . }}
|
||||
{{- range .Tests }}
|
||||
| {{ template "status_icon" .Status }} | `{{ .Name }}` | `{{ $suite.Name }}` |
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
{{if or (gt .Totals.Error 0) (gt .Totals.Failed 0) }}
|
||||
#### Errors
|
||||
{{end}}
|
||||
|
||||
{{- range .Tests }}
|
||||
{{ if or ( eq .Status "error" ) (eq .Status "failed" ) }}
|
||||
<details>
|
||||
<summary>`{{ .Name -}}`</summary>
|
||||
|
||||
**Output**
|
||||
|
||||
```
|
||||
{{ .Error -}}
|
||||
```
|
||||
|
||||
</details>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{- range .Suites }}
|
||||
{{- $suite := . }}
|
||||
{{- range .Tests }}
|
||||
{{ if or ( eq .Status "error" ) (eq .Status "failed" ) }}
|
||||
<details>
|
||||
<summary>`{{ .Name -}}`</summary>
|
||||
|
||||
**Suite**
|
||||
|
||||
```
|
||||
{{ $suite.Name }}
|
||||
```
|
||||
|
||||
**Output**
|
||||
|
||||
```
|
||||
{{ .Error -}}
|
||||
```
|
||||
</details>
|
||||
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
{{end}}
|
||||
|
||||
|
||||
{{end -}}
|
||||
|
||||
{{define "status_icon"}}
|
||||
{{- if eq . "passed" -}}✓{{- end -}}
|
||||
{{- if or (eq . "error") (eq . "failed") -}}⨯{{- end -}}
|
||||
{{- if eq . "skipped" -}}⏩{{- end -}}
|
||||
{{end}}
|
Reference in New Issue
Block a user