-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (60 loc) · 1.67 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/debug"
"github.com/becheran/go-testreport/internal/args"
"github.com/becheran/go-testreport/internal/report"
)
func main() {
flag.Usage = func() {
info, ok := debug.ReadBuildInfo()
if ok {
fmt.Printf("go-testreport (Version: %s)", info.Main.Version)
}
fmt.Fprintf(os.Stderr, "Usage %s [<options>] <file>:\n", os.Args[0])
flag.PrintDefaults()
}
var templateFile string
var vars string
flag.StringVar(&templateFile, "template", "", "Template file for the report generation. If not set, the default template will be applied")
flag.StringVar(&vars, "vars", "", "Comma separated list of custom variables which can be used in the template. For example -vars=\"Title:Custom Title\"")
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
filepath := flag.Args()[0]
file, err := os.OpenFile(filepath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
log.Fatalf("Failed to open file %s. %s", filepath, err)
}
defer file.Close()
tmp, err := report.GetTemplate(templateFile)
if err != nil {
log.Fatalf("Invalid template. %s", err)
}
result, err := report.ParseTestJson(os.Stdin)
if err != nil {
log.Fatalf("Failed to parse test result %s", err)
}
result.Vars, err = args.ParseCommaSeparatedList(vars)
if err != nil {
log.Fatalf("Failed to parse variables. %s", err)
}
if err := report.CreateReport(result, file, tmp); err != nil {
log.Fatalf("Failed to create test report. %s", err)
}
failed := false
for _, packRes := range result.PackageResult {
fmt.Println(packRes)
if packRes.PackageResult == report.FTSFail {
failed = true
}
}
if failed {
os.Exit(1)
}
}