generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add junit report + buildkite upload (#68)
Fixes #65 and re-arranged some stuff: * split out all report renders to their own file * update result struct to track per-test runtime * disable failing web5-kt test * use web5-js test from web5-js repo, drop web5-js test from this repo * renamed the go package to reflect the current repo name
- Loading branch information
1 parent
5385c51
commit df9d113
Showing
29 changed files
with
349 additions
and
2,990 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/TBD54566975/web5-spec | ||
module github.com/TBD54566975/sdk-development | ||
|
||
go 1.20 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package reports | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"golang.org/x/exp/slog" | ||
) | ||
|
||
func sanatizeHTML(dirty error) string { | ||
clean := strings.ReplaceAll(dirty.Error(), "<", "<") | ||
clean = strings.ReplaceAll(clean, ">", ">") | ||
clean = strings.ReplaceAll(clean, "\n", "\\\\n") | ||
|
||
return clean | ||
} | ||
|
||
type htmlTemplateInput struct { | ||
Reports []Report | ||
Tests map[string][]string | ||
} | ||
|
||
func WriteHTML(reports []Report, filename string) error { | ||
slog.Info("writing html report") | ||
|
||
testmap := make(map[string]map[string]bool) | ||
for _, report := range reports { | ||
for category, tests := range report.Results { | ||
if _, ok := tests[category]; !ok { | ||
testmap[category] = map[string]bool{} | ||
} | ||
|
||
for test := range tests { | ||
testmap[category][test] = true | ||
} | ||
} | ||
} | ||
|
||
templateInput := htmlTemplateInput{ | ||
Reports: reports, | ||
Tests: make(map[string][]string), | ||
} | ||
|
||
for category, tests := range testmap { | ||
for test := range tests { | ||
templateInput.Tests[category] = append(templateInput.Tests[category], test) | ||
} | ||
} | ||
|
||
f, err := os.Create(filename) | ||
if err != nil { | ||
return fmt.Errorf("error opening %s: %v", filename, err) | ||
} | ||
defer f.Close() | ||
|
||
if err := htmlTemplates.ExecuteTemplate(f, "report-template.html", templateInput); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package reports | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"time" | ||
) | ||
|
||
func durationToJunit(t time.Duration) string { | ||
return fmt.Sprintf("%f", float64(t)/float64(time.Second)) | ||
} | ||
|
||
type junitTemplateInput struct { | ||
TimeTotal time.Duration | ||
TimePerTestSuite map[string]time.Duration | ||
Report Report | ||
} | ||
|
||
func WriteJunitToFile(report Report, filename string) error { | ||
f, err := os.Create(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
if err := WriteJunit(report, f); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func WriteJunit(report Report, writer io.Writer) error { | ||
templateInput := junitTemplateInput{ | ||
Report: report, | ||
TimePerTestSuite: map[string]time.Duration{}, | ||
} | ||
|
||
for testsuite, results := range report.Results { | ||
var testsuiteTime time.Duration | ||
for _, result := range results { | ||
testsuiteTime = testsuiteTime + result.Time | ||
templateInput.TimeTotal = templateInput.TimeTotal + result.Time | ||
} | ||
|
||
templateInput.TimePerTestSuite[testsuite] = testsuiteTime | ||
} | ||
|
||
if err := textTemplates.ExecuteTemplate(writer, "report-template.junit.xml", templateInput); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package reports | ||
|
||
import "os" | ||
|
||
func WriteMarkdown(report Report, filename string) error { | ||
f, err := os.Create(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
err = textTemplates.ExecuteTemplate(f, "report-template.md", report) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites time="{{ .TimeTotal | durationToJunit }}"> | ||
{{ range $testSuiteName, $tests := .Report.Results }} | ||
<testsuite name="{{ $testSuiteName }}" tests="{{ $tests | len }}" time="{{ index $.TimePerTestSuite $testSuiteName | durationToJunit }}"> | ||
{{ range $testCaseName, $result := $tests }} | ||
<testcase name="{{ $testCaseName }}" classname="{{ $testSuiteName }}" time="{{ $result.Time | durationToJunit }}"{{ if $result.Errors }}> | ||
{{ if $result.IsSkipped }} | ||
<skipped message="test is not supported by this SDK" /> | ||
{{ else }} | ||
<failure message="test did not pass" type="AssertionError"> | ||
{{ range $_, $err := $result.Errors }}{{ $err }}{{ end }} | ||
</failure> | ||
{{ end }} | ||
</testcase> | ||
{{ else }}/>{{ end}} | ||
{{ end }} | ||
</testsuite> | ||
{{ end }} | ||
</testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.