Initial commit

This commit is contained in:
2019-11-14 16:32:21 +01:00
commit ca235b53af
6 changed files with 255 additions and 0 deletions

56
cmd/junit2md/main.go Normal file
View 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"))
}
}

View 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" -}}&#10003;{{- end -}}
{{- if or (eq . "error") (eq . "failed") -}}&#10799;{{- end -}}
{{- if eq . "skipped" -}}&#9193;{{- end -}}
{{end}}