-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreporter.go
80 lines (68 loc) · 2.47 KB
/
reporter.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
package main
import (
"encoding/json"
"os"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/types"
)
// JSONReporter is a custom reporter for Ginkgo to output the test results
// into a JSON file with custom fields.
type JSONReporter struct {
}
// JSON is a struct containing the information that we will output into
// the report JSON file.
type JSON struct {
Name string `json:"name"`
Library string `json:"library"`
NumMessages int `json:"numMessages"`
SizeMessages int `json:"sizeMessages"`
NumSamples int `json:"numberOfSamples"`
Results []float64 `json:"results"`
Smallest interface{} `json:"smallest"`
Largest interface{} `json:"largest"`
Average interface{} `json:"average"`
StdDeviation interface{} `json:"stdDeviation"`
}
// NewJSONReporter returns a new JSONReporter instance.
func NewJSONReporter() *JSONReporter {
return &JSONReporter{}
}
// SpecDidComplete implements the ginkgo.Reporter interface. It runs when the tests have passed,
// allowing us to output the information into an output JSON file.
func (reporter *JSONReporter) SpecDidComplete(specSummary *types.SpecSummary) {
switch specSummary.State {
case types.SpecStatePassed:
report := JSON{
Library: Library,
NumMessages: NumMessages,
SizeMessages: MessageSize,
NumSamples: specSummary.NumberOfSamples,
}
for _, value := range specSummary.Measurements {
report.Name = value.Name
report.Results = value.Results
report.Smallest = value.Smallest
report.Largest = value.Largest
report.Average = value.Average
report.StdDeviation = value.StdDeviation
}
data, _ := json.Marshal(report)
f, _ := os.Create("results.json")
f.WriteString(string(data))
}
}
// SpecSuiteWillBegin implements the ginkgo.Reporter interface.
func (reporter *JSONReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
}
// BeforeSuiteDidRun implements the ginkgo.Reporter interface.
func (reporter *JSONReporter) BeforeSuiteDidRun(setupSummary *types.SetupSummary) {
}
// AfterSuiteDidRun implements the ginkgo.Reporter interface.
func (reporter *JSONReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
}
// SpecWillRun implements the ginkgo.Reporter interface.
func (reporter *JSONReporter) SpecWillRun(specSummary *types.SpecSummary) {
}
// SpecSuiteDidEnd implements the ginkgo.Reporter interface.
func (reporter *JSONReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
}