File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,19 +7,39 @@ import (
77 "io"
88 "os"
99 "strings"
10+ "time"
11+
12+ "github.com/google/uuid"
1013)
1114
1215type Report struct {
13- Results * Results `json:"results"`
16+ ReportFormat string `json:"reportFormat"`
17+ SpecVersion string `json:"specVersion"`
18+ ReportId string `json:"reportId,omitempty"`
19+ Timestamp time.Time `json:"timestamp,omitempty"`
20+ GeneratedBy string `json:"generatedBy,omitempty"`
21+ Results * Results `json:"results"`
22+ Extra interface {} `json:"extra,omitempty"`
1423}
1524
25+ const (
26+ ReportFormatCTRF = "CTRF"
27+ SpecVersionCTRF = "0.0.0"
28+ GeneratedByDefault = "go-ctrf-json-reporter"
29+ )
30+
1631func NewReport (toolName string , env * Environment ) * Report {
1732 return & Report {
33+ ReportFormat : ReportFormatCTRF ,
34+ SpecVersion : SpecVersionCTRF ,
35+ ReportId : uuid .New ().String (),
36+ Timestamp : time .Now (),
1837 Results : & Results {
1938 Tool : & Tool {Name : toolName },
2039 Environment : env ,
2140 Summary : & Summary {},
2241 },
42+ GeneratedBy : GeneratedByDefault ,
2343 }
2444}
2545
Original file line number Diff line number Diff line change @@ -2,16 +2,19 @@ package ctrf
22
33import (
44 "encoding/json"
5- "gopkg.in/yaml.v3"
65 "os"
76 "testing"
87
8+ "gopkg.in/yaml.v3"
9+
910 "github.com/stretchr/testify/assert"
1011)
1112
1213func TestRequiredProperties (t * testing.T ) {
1314 // Arrange
1415 report := Report {
16+ ReportFormat : ReportFormatCTRF ,
17+ SpecVersion : SpecVersionCTRF ,
1518 Results : & Results {
1619 Tool : & Tool {
1720 Name : "my tool" ,
@@ -57,6 +60,9 @@ func TestRequiredProperties(t *testing.T) {
5760 }
5861
5962 expectedJson := `{
63+ "reportFormat": "CTRF",
64+ "specVersion": "0.0.0",
65+ "timestamp": "0001-01-01T00:00:00Z",
6066 "results": {
6167 "tool": {
6268 "name": "my tool"
Original file line number Diff line number Diff line change @@ -2,9 +2,13 @@ module github.com/ctrf-io/go-ctrf-json-reporter
22
33go 1.19
44
5+ require (
6+ github.com/google/uuid v1.6.0
7+ github.com/stretchr/testify v1.9.0
8+ gopkg.in/yaml.v3 v3.0.1
9+ )
10+
511require (
612 github.com/davecgh/go-spew v1.1.1 // indirect
713 github.com/pmezard/go-difflib v1.0.0 // indirect
8- github.com/stretchr/testify v1.9.0 // indirect
9- gopkg.in/yaml.v3 v3.0.1 // indirect
1014)
Original file line number Diff line number Diff line change 11github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
22github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
3+ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0 =
4+ github.com/google/uuid v1.6.0 /go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo =
35github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
46github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
57github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg =
68github.com/stretchr/testify v1.9.0 /go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY =
9+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM =
710gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
811gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
912gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
You can’t perform that action at this time.
0 commit comments