-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
html_report_test.go
123 lines (91 loc) · 3.68 KB
/
html_report_test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package benchmarks
import (
"crypto/sha256"
html_report "github.com/daveshanley/vacuum/html-report"
"github.com/daveshanley/vacuum/model"
"github.com/daveshanley/vacuum/motor"
"github.com/daveshanley/vacuum/rulesets"
"github.com/daveshanley/vacuum/statistics"
"os"
"testing"
)
func BenchmarkHtmlReport_GenerateReport(b *testing.B) {
specBytes, _ := os.ReadFile("../model/test_files/stripe.yaml")
defaultRuleSets := rulesets.BuildDefaultRuleSets()
// default is recommended rules, based on spectral (for now anyway)
selectedRS := defaultRuleSets.GenerateOpenAPIRecommendedRuleSet()
ruleset := motor.ApplyRulesToRuleSet(&motor.RuleSetExecution{
RuleSet: selectedRS,
Spec: specBytes,
})
resultSet := model.NewRuleResultSet(ruleset.Results)
resultSet.SortResultsByLineNumber()
// generate statistics
stats := statistics.CreateReportStatistics(ruleset.Index, ruleset.SpecInfo, resultSet)
for n := 0; n < b.N; n++ {
// generate html report
report := html_report.NewHTMLReport(ruleset.Index, ruleset.SpecInfo, resultSet, stats, false)
report.GenerateReport(true, "")
}
}
func BenchmarkHtmlReport_GenerateReportIdentical(b *testing.B) {
specBytes, _ := os.ReadFile("../model/test_files/pegel-online-api.yaml")
defaultRuleSets := rulesets.BuildDefaultRuleSets()
// default is recommended rules, based on spectral (for now anyway)
selectedRS := defaultRuleSets.GenerateOpenAPIRecommendedRuleSet()
ruleset := motor.ApplyRulesToRuleSet(&motor.RuleSetExecution{
RuleSet: selectedRS,
Spec: specBytes,
})
resultSet := model.NewRuleResultSet(ruleset.Results)
resultSet.SortResultsByLineNumber()
// generate statistics
stats := statistics.CreateReportStatistics(ruleset.Index, ruleset.SpecInfo, resultSet)
for n := 0; n < b.N; n++ {
// generate html reports and compare hash
reportA := html_report.NewHTMLReport(ruleset.Index, ruleset.SpecInfo, resultSet, stats, true)
reportABytes := reportA.GenerateReport(false, "")
reportB := html_report.NewHTMLReport(ruleset.Index, ruleset.SpecInfo, resultSet, stats, true)
reportBBytes := reportB.GenerateReport(false, "")
hashA := sha256.Sum256(reportABytes)
hashB := sha256.Sum256(reportBBytes)
if hashA != hashB {
panic("failed identical check")
}
}
}
func TestHtmlReport_GenerateReportIdenticalRun200(t *testing.T) {
specBytes, _ := os.ReadFile("../model/test_files/pegel-online-api.yaml")
defaultRuleSets := rulesets.BuildDefaultRuleSets()
// default is recommended rules, based on spectral (for now anyway)
selectedRS := defaultRuleSets.GenerateOpenAPIRecommendedRuleSet()
ruleset := motor.ApplyRulesToRuleSet(&motor.RuleSetExecution{
RuleSet: selectedRS,
Spec: specBytes,
})
resultSet := model.NewRuleResultSet(ruleset.Results)
resultSet.SortResultsByLineNumber()
// generate statistics
stats := statistics.CreateReportStatistics(ruleset.Index, ruleset.SpecInfo, resultSet)
reportZero := html_report.NewHTMLReport(ruleset.Index, ruleset.SpecInfo, resultSet, stats, true)
reportZeroBytes := reportZero.GenerateReport(false, "")
hashZero := sha256.Sum256(reportZeroBytes)
for n := 0; n < 200; n++ {
// generate html reports and compare hash
reportA := html_report.NewHTMLReport(ruleset.Index, ruleset.SpecInfo, resultSet, stats, true)
reportABytes := reportA.GenerateReport(false, "")
reportB := html_report.NewHTMLReport(ruleset.Index, ruleset.SpecInfo, resultSet, stats, true)
reportBBytes := reportB.GenerateReport(false, "")
hashA := sha256.Sum256(reportABytes)
hashB := sha256.Sum256(reportBBytes)
if hashA != hashB {
panic("failed identical check")
}
if hashA != hashZero {
panic("failed identical check")
}
if hashB != hashZero {
panic("failed identical check")
}
}
}