Skip to content

Commit

Permalink
Handle tbdex test results
Browse files Browse the repository at this point in the history
Co-authored-by: Finn Herzfeld <[email protected]>
  • Loading branch information
phoebe-lew and finn-block committed Jan 9, 2024
1 parent e4d8b37 commit 684c7cb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
23 changes: 19 additions & 4 deletions reports/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,38 @@ func sanatizeHTML(dirty error) string {
type htmlTemplateInput struct {
Reports []Report
Web5Tests map[string][]string
TbdexTests map[string][]string
TbDEXTests map[string][]string
}

func WriteHTML(reports []Report, filename string) error {
slog.Info("writing html report", "reports", len(reports))

testmap := make(map[string]map[string]bool)
tbdexTestMap := 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{}
if report.SDK.Type == "web5" {
testmap[category] = map[string]bool{}
} else {
tbdexTestMap[category] = map[string]bool{}
}
}

for test := range tests {
testmap[category][test] = true
if report.SDK.Type == "web5" {
testmap[category][test] = true
} else {
tbdexTestMap[category][test] = true
}
}
}
}

templateInput := htmlTemplateInput{
Reports: reports,
Web5Tests: make(map[string][]string),
TbdexTests: make(map[string][]string),
TbDEXTests: make(map[string][]string),
}

for category, tests := range testmap {
Expand All @@ -50,6 +59,12 @@ func WriteHTML(reports []Report, filename string) error {
}
}

for category, tests := range tbdexTestMap {
for test := range tests {
templateInput.TbDEXTests[category] = append(templateInput.TbDEXTests[category], test)
}
}

f, err := os.Create(filename)
if err != nil {
return fmt.Errorf("error opening %s: %v", filename, err)
Expand Down
4 changes: 2 additions & 2 deletions reports/report-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<main>
<h1>web5 spec compliance report</h1>

{{ range $category, $tests := .Tests }}
{{ range $category, $tests := .Web5Tests }}
<h2 id="{{ $category }}_table-caption">{{ $category }}</h2>
<table aria-labelledby="{{ $category }}_table-caption">
<colgroup>
Expand Down Expand Up @@ -56,7 +56,7 @@ <h2 id="{{ $category }}_table-caption">{{ $category }}</h2>

<h1>tbdex spec compliance report</h1>

{{ range $category, $tests := .Tests }}
{{ range $category, $tests := .TbdexTests }}
<h2 id="{{ $category }}_table-caption">{{ $category }}</h2>
<table aria-labelledby="{{ $category }}_table-caption">
<colgroup>
Expand Down
1 change: 1 addition & 0 deletions reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type SDKMeta struct {
FeatureRegex *regexp.Regexp
VectorRegex *regexp.Regexp
VectorPath string
Type string
}

type Report struct {
Expand Down
4 changes: 4 additions & 0 deletions reports/sdks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
FeatureRegex: regexp.MustCompile(`Web5TestVectors(\w+)`),
VectorRegex: regexp.MustCompile(`\w+ \w+ (\w+)`),
VectorPath: "test-vectors",
Type: "web5",
},
{
Name: "web5-kt",
Expand All @@ -28,6 +29,7 @@ var (
FeatureRegex: regexp.MustCompile(`web5\.sdk\.\w+.Web5TestVectors(\w+)`),
VectorRegex: regexp.MustCompile(`(\w+)\(\)`),
VectorPath: "test-vectors",
Type: "web5",
},
{
Name: "tbdex-js",
Expand All @@ -36,6 +38,7 @@ var (
FeatureRegex: regexp.MustCompile(`TbdexTestVectors(\w+)`),
VectorRegex: regexp.MustCompile(`\w+ \w+ (\w+)`),
VectorPath: "test-vectors",
Type: "tbdex",
},
{
Name: "tbdex-kt",
Expand All @@ -44,6 +47,7 @@ var (
FeatureRegex: regexp.MustCompile(`tbdex\.sdk\.\w+.TbdexTestVectors(\w+)`),
VectorRegex: regexp.MustCompile(`(\w+)\(\)`),
VectorPath: "test-vectors",
Type: "tbdex",
},
}
)
Expand Down

0 comments on commit 684c7cb

Please sign in to comment.