Skip to content

Commit

Permalink
Merge pull request #21 from medyagh/json_output
Browse files Browse the repository at this point in the history
add short summary to outputfile and add durations
  • Loading branch information
medyagh authored Jan 15, 2021
2 parents b8c0318 + 3c0ec81 commit 96570e2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ generate_json:
test: build
rm ./out/output.html || true
rm ./out/output2.html || true
.${BINARY} -name "KVM Linux" -repo "github.com/kubernetes/minikube/" -pr "6096" -in "testdata/minikube-logs.json" -out "./out/output.html" -details "0c07e808219403a7241ee5a0fc6a85a897594339"
.${BINARY} -name "KVM Linux" -repo "github.com/kubernetes/minikube/" -pr "6096" -in "testdata/Docker_Linux.json" -out "./out/output2.html" -details "0c07e808219403a7241ee5a0fc6a85a897594339"
.${BINARY} -name "KVM Linux" -repo "github.com/kubernetes/minikube/" -pr "6096" -in "testdata/minikube-logs.json" -out_html "./out/output.html" -out_summary out/output_summary.json -details "0c07e808219403a7241ee5a0fc6a85a897594339"
.${BINARY} -name "KVM Linux" -repo "github.com/kubernetes/minikube/" -pr "6096" -in "testdata/Docker_Linux.json" -out_html "./out/output2.html" -out_summary out/output2_summary.json "0c07e808219403a7241ee5a0fc6a85a897594339"
.${BINARY} -name "KVM Linux" -repo "github.com/kubernetes/minikube/" -pr "6096" -in "testdata/Docker_Linux.json" -out_html "./out/output2NoSummary.html" "0c07e808219403a7241ee5a0fc6a85a897594339"


.PHONY: cross
Expand Down
33 changes: 22 additions & 11 deletions cmd/gopogh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import (
var Build string

var (
reportName = flag.String("name", "", "report name ")
reportPR = flag.String("pr", "", "Pull request number")
reportDetails = flag.String("details", "", "report details (for example test args...)")
reportRepo = flag.String("repo", "", "source repo")
inPath = flag.String("in", "", "path to JSON input file")
outPath = flag.String("out", "", "path to HTML output file")
version = flag.Bool("version", false, "shows version")
reportName = flag.String("name", "", "report name ")
reportPR = flag.String("pr", "", "Pull request number")
reportDetails = flag.String("details", "", "report details (for example test args...)")
reportRepo = flag.String("repo", "", "source repo")
inPath = flag.String("in", "", "path to JSON file produced by go tool test2json")
outPath = flag.String("out", "", "(depricated use -out_html instead) path to HTML output file ")
outHTMLPath = flag.String("out_html", "", "path to HTML output file")
outSummaryPath = flag.String("out_summary", "", "path to json summary output file")
version = flag.Bool("version", false, "shows version")
)

func main() {
Expand All @@ -32,7 +34,12 @@ func main() {
if *inPath == "" {
panic("must provide path to JSON input file")
}
if *outPath == "" {

if *outPath != "" {
*outHTMLPath = *outPath
}

if *outHTMLPath == "" {
panic("must provide path to HTML output file")
}

Expand All @@ -51,15 +58,19 @@ func main() {
if err != nil {
fmt.Printf("failed to convert report to html: %v", err)
} else {
if err := ioutil.WriteFile(*outPath, html, 0644); err != nil {
panic(fmt.Sprintf("failed to write the html output %s: %v", *outPath, err))
if err := ioutil.WriteFile(*outHTMLPath, html, 0644); err != nil {
panic(fmt.Sprintf("failed to write the html output %s: %v", *outHTMLPath, err))
}
}

j, err := c.ShortSummary()
if err != nil {
fmt.Printf("failed to convert report to json: %v", err)
} else {
if *outSummaryPath != "" {
if err := ioutil.WriteFile(*outSummaryPath, j, 0644); err != nil {
panic(fmt.Sprintf("failed to write the html output %s: %v", *outSummaryPath, err))
}
}
fmt.Println(string(j))
}
}
17 changes: 11 additions & 6 deletions pkg/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,36 @@ func (c DisplayContent) ShortSummary() ([]byte, error) {
NumberOfSkip int
FailedTests []string
PassedTests []string
SkippedTests []string
Durations map[string]float64
GopoghVersion string
GopoghBuild string
Detail models.ReportDetail
}
ss := shortSummary{}
ss.Durations = make(map[string]float64)
for _, t := range resultTypes {
if t == pass {
ss.NumberOfPass = len(c.Results[t])
for _, ti := range c.Results[t] {
ss.PassedTests = append(ss.PassedTests, ti.TestName)
ss.Durations[ti.TestName] = ti.Duration
}
}
if t == fail {
ss.NumberOfFail = len(c.Results[t])
for _, ti := range c.Results[t] {
ss.FailedTests = append(ss.FailedTests, ti.TestName)
ss.Durations[ti.TestName] = ti.Duration
}
}
if t == skip {
ss.NumberOfSkip = len(c.Results[t])
for _, ti := range c.Results[t] {
ss.SkippedTests = append(ss.SkippedTests, ti.TestName)
// not adding to the skip test durations to avoid confusion or bad data, since they will be 0seconds most-likely
// but if I change my mind we need to uncomment this line
// ss.Durations[ti.TestName] = ti.Duration
}
}

}
Expand All @@ -58,11 +68,6 @@ func (c DisplayContent) ShortSummary() ([]byte, error) {
return json.MarshalIndent(ss, "", " ")
}

// JSON return the report in json
func (c DisplayContent) JSON() ([]byte, error) {
return json.MarshalIndent(c, "", " ")
}

// HTML returns html format
func (c DisplayContent) HTML() ([]byte, error) {

Expand Down

0 comments on commit 96570e2

Please sign in to comment.