diff --git a/go.mod b/go.mod index dcae1a2c3b..68e88cea1d 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/maxbrunsfeld/counterfeiter/v6 v6.12.0 github.com/mitchellh/hashstructure v1.1.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/onsi/ginkgo/v2 v2.25.3 + github.com/onsi/ginkgo/v2 v2.26.0 github.com/onsi/gomega v1.38.2 github.com/openshift/api v3.9.0+incompatible github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a diff --git a/go.sum b/go.sum index 7ac539e9cc..8fadc3dfbe 100644 --- a/go.sum +++ b/go.sum @@ -186,6 +186,12 @@ github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj2 github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gkampitakis/ciinfo v0.3.2 h1:JcuOPk8ZU7nZQjdUhctuhQofk7BGHuIy0c9Ez8BNhXs= +github.com/gkampitakis/ciinfo v0.3.2/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo= +github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M= +github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk= +github.com/gkampitakis/go-snaps v0.5.14 h1:3fAqdB6BCPKHDMHAKRwtPUwYexKtGrNuw8HX/T/4neo= +github.com/gkampitakis/go-snaps v0.5.14/go.mod h1:HNpx/9GoKisdhw9AFOBT1N7DBs9DiHo/hGheFGBZ+mc= github.com/go-air/gini v1.0.4 h1:lteMAxHKNOAjIqazL/klOJJmxq6YxxSuJ17MnMXny+s= github.com/go-air/gini v1.0.4/go.mod h1:dd8RvT1xcv6N1da33okvBd8DhMh1/A4siGy6ErjTljs= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= @@ -227,6 +233,8 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/gobuffalo/flect v1.0.3 h1:xeWBM2nui+qnVvNM4S3foBhCAL2XgPU+a7FdpelbTq4= github.com/gobuffalo/flect v1.0.3/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs= +github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= +github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= @@ -374,6 +382,8 @@ github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbd github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/joshdk/go-junit v1.0.0 h1:S86cUKIdwBHWwA6xCmFlf3RTLfVXYQfvanM5Uh+K6GE= +github.com/joshdk/go-junit v1.0.0/go.mod h1:TiiV0PqkaNfFXjEiyjWM3XXrhVyCa1K4Zfga6W52ung= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= @@ -404,6 +414,8 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= +github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo= +github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= @@ -415,6 +427,8 @@ github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuE github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/maxbrunsfeld/counterfeiter/v6 v6.12.0 h1:aOeI7xAOVdK+R6xbVsZuU9HmCZYmQVmZgPf9xJUd2Sg= github.com/maxbrunsfeld/counterfeiter/v6 v6.12.0/go.mod h1:0hZWbtfeCYUQeAQdPLUzETiBhUSns7O6LDj9vH88xKA= +github.com/mfridman/tparse v0.18.0 h1:wh6dzOKaIwkUGyKgOntDW4liXSo37qg5AXbIhkMV3vE= +github.com/mfridman/tparse v0.18.0/go.mod h1:gEvqZTuCgEhPbYk/2lS3Kcxg1GmTxxU7kTC8DvP0i/A= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0= @@ -459,8 +473,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU= -github.com/onsi/ginkgo/v2 v2.25.3 h1:Ty8+Yi/ayDAGtk4XxmmfUy4GabvM+MegeB4cDLRi6nw= -github.com/onsi/ginkgo/v2 v2.25.3/go.mod h1:43uiyQC4Ed2tkOzLsEYm7hnrb7UJTWHYNsuy3bG/snE= +github.com/onsi/ginkgo/v2 v2.26.0 h1:1J4Wut1IlYZNEAWIV3ALrT9NfiaGW2cDCJQSFQMs/gE= +github.com/onsi/ginkgo/v2 v2.26.0/go.mod h1:qhEywmzWTBUY88kfO0BRvX4py7scov9yR+Az2oavUzw= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= @@ -563,6 +577,14 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/tidwall/btree v1.8.1 h1:27ehoXvm5AG/g+1VxLS1SD3vRhp/H7LuEfwNvddEdmA= github.com/tidwall/btree v1.8.1/go.mod h1:jBbTdUWhSZClZWoDg54VnvV7/54modSOzDN7VXftj1A= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 h1:e/5i7d4oYZ+C1wj2THlRK+oAhjeS/TRQwMfkIuet3w0= github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399/go.mod h1:LdwHTNJT99C5fTAzDz0ud328OgXz+gierycbcIx2fRs= github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE= diff --git a/vendor/github.com/onsi/ginkgo/v2/CHANGELOG.md b/vendor/github.com/onsi/ginkgo/v2/CHANGELOG.md index 0e5f23782f..9db388356c 100644 --- a/vendor/github.com/onsi/ginkgo/v2/CHANGELOG.md +++ b/vendor/github.com/onsi/ginkgo/v2/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.26.0 + +### Features + +Ginkgo can now generate json-formatted reports that are compatible with the `go test` json format. Use `ginkgo --gojson-report=report.go.json`. This is not intended to be a replacement for Ginkgo's native json format which is more information rich and better models Ginkgo's test structure semantics. + ## 2.25.3 ### Fixes diff --git a/vendor/github.com/onsi/ginkgo/v2/README.md b/vendor/github.com/onsi/ginkgo/v2/README.md index e3d0c13cc6..7b7ab9e39c 100644 --- a/vendor/github.com/onsi/ginkgo/v2/README.md +++ b/vendor/github.com/onsi/ginkgo/v2/README.md @@ -113,3 +113,13 @@ Ginkgo is MIT-Licensed ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) + +## Sponsors + +Sponsors commit to a [sponsorship](https://github.com/sponsors/onsi) for a year. If you're an organization that makes use of Ginkgo please consider becoming a sponsor! + +

Browser testing via + + + +

diff --git a/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/profiles_and_reports.go b/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/profiles_and_reports.go index 8e16d2bb03..f3439a3f0c 100644 --- a/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/profiles_and_reports.go +++ b/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/profiles_and_reports.go @@ -90,6 +90,9 @@ func FinalizeProfilesAndReportsForSuites(suites TestSuites, cliConfig types.CLIC if reporterConfig.JSONReport != "" { reportFormats = append(reportFormats, reportFormat{ReportName: reporterConfig.JSONReport, GenerateFunc: reporters.GenerateJSONReport, MergeFunc: reporters.MergeAndCleanupJSONReports}) } + if reporterConfig.GoJSONReport != "" { + reportFormats = append(reportFormats, reportFormat{ReportName: reporterConfig.GoJSONReport, GenerateFunc: reporters.GenerateGoTestJSONReport, MergeFunc: reporters.MergeAndCleanupGoTestJSONReports}) + } if reporterConfig.JUnitReport != "" { reportFormats = append(reportFormats, reportFormat{ReportName: reporterConfig.JUnitReport, GenerateFunc: reporters.GenerateJUnitReport, MergeFunc: reporters.MergeAndCleanupJUnitReports}) } diff --git a/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/run.go b/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/run.go index 41052ea19d..30d8096cd6 100644 --- a/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/run.go +++ b/vendor/github.com/onsi/ginkgo/v2/ginkgo/internal/run.go @@ -107,6 +107,9 @@ func runSerial(suite TestSuite, ginkgoConfig types.SuiteConfig, reporterConfig t if reporterConfig.JSONReport != "" { reporterConfig.JSONReport = AbsPathForGeneratedAsset(reporterConfig.JSONReport, suite, cliConfig, 0) } + if reporterConfig.GoJSONReport != "" { + reporterConfig.GoJSONReport = AbsPathForGeneratedAsset(reporterConfig.GoJSONReport, suite, cliConfig, 0) + } if reporterConfig.JUnitReport != "" { reporterConfig.JUnitReport = AbsPathForGeneratedAsset(reporterConfig.JUnitReport, suite, cliConfig, 0) } @@ -179,6 +182,9 @@ func runParallel(suite TestSuite, ginkgoConfig types.SuiteConfig, reporterConfig if reporterConfig.JSONReport != "" { reporterConfig.JSONReport = AbsPathForGeneratedAsset(reporterConfig.JSONReport, suite, cliConfig, 0) } + if reporterConfig.GoJSONReport != "" { + reporterConfig.GoJSONReport = AbsPathForGeneratedAsset(reporterConfig.GoJSONReport, suite, cliConfig, 0) + } if reporterConfig.JUnitReport != "" { reporterConfig.JUnitReport = AbsPathForGeneratedAsset(reporterConfig.JUnitReport, suite, cliConfig, 0) } diff --git a/vendor/github.com/onsi/ginkgo/v2/ginkgo/main.go b/vendor/github.com/onsi/ginkgo/v2/ginkgo/main.go index bd6b8fbff3..419589b48c 100644 --- a/vendor/github.com/onsi/ginkgo/v2/ginkgo/main.go +++ b/vendor/github.com/onsi/ginkgo/v2/ginkgo/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - _ "go.uber.org/automaxprocs" "github.com/onsi/ginkgo/v2/ginkgo/build" "github.com/onsi/ginkgo/v2/ginkgo/command" "github.com/onsi/ginkgo/v2/ginkgo/generators" diff --git a/vendor/github.com/onsi/ginkgo/v2/ginkgo/maxprocs.go b/vendor/github.com/onsi/ginkgo/v2/ginkgo/maxprocs.go new file mode 100644 index 0000000000..a7d2b37d6b --- /dev/null +++ b/vendor/github.com/onsi/ginkgo/v2/ginkgo/maxprocs.go @@ -0,0 +1,8 @@ +//go:build !go1.25 +// +build !go1.25 + +package main + +import ( + _ "go.uber.org/automaxprocs" +) diff --git a/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson.go b/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson.go new file mode 100644 index 0000000000..8b7a9ceabf --- /dev/null +++ b/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson.go @@ -0,0 +1,158 @@ +package reporters + +import ( + "errors" + "fmt" + "strings" + "time" + + "github.com/onsi/ginkgo/v2/types" + "golang.org/x/tools/go/packages" +) + +func ptr[T any](in T) *T { + return &in +} + +type encoder interface { + Encode(v any) error +} + +// gojsonEvent matches the format from go internals +// https://github.com/golang/go/blob/master/src/cmd/internal/test2json/test2json.go#L31-L41 +// https://pkg.go.dev/cmd/test2json +type gojsonEvent struct { + Time *time.Time `json:",omitempty"` + Action GoJSONAction + Package string `json:",omitempty"` + Test string `json:",omitempty"` + Elapsed *float64 `json:",omitempty"` + Output *string `json:",omitempty"` + FailedBuild string `json:",omitempty"` +} + +type GoJSONAction string + +const ( + // start - the test binary is about to be executed + GoJSONStart GoJSONAction = "start" + // run - the test has started running + GoJSONRun GoJSONAction = "run" + // pause - the test has been paused + GoJSONPause GoJSONAction = "pause" + // cont - the test has continued running + GoJSONCont GoJSONAction = "cont" + // pass - the test passed + GoJSONPass GoJSONAction = "pass" + // bench - the benchmark printed log output but did not fail + GoJSONBench GoJSONAction = "bench" + // fail - the test or benchmark failed + GoJSONFail GoJSONAction = "fail" + // output - the test printed output + GoJSONOutput GoJSONAction = "output" + // skip - the test was skipped or the package contained no tests + GoJSONSkip GoJSONAction = "skip" +) + +func goJSONActionFromSpecState(state types.SpecState) GoJSONAction { + switch state { + case types.SpecStateInvalid: + return GoJSONFail + case types.SpecStatePending: + return GoJSONSkip + case types.SpecStateSkipped: + return GoJSONSkip + case types.SpecStatePassed: + return GoJSONPass + case types.SpecStateFailed: + return GoJSONFail + case types.SpecStateAborted: + return GoJSONFail + case types.SpecStatePanicked: + return GoJSONFail + case types.SpecStateInterrupted: + return GoJSONFail + case types.SpecStateTimedout: + return GoJSONFail + default: + panic("unexpected state should not happen") + } +} + +// gojsonReport wraps types.Report and calcualtes extra fields requires by gojson +type gojsonReport struct { + o types.Report + // Extra calculated fields + goPkg string + elapsed float64 +} + +func newReport(in types.Report) *gojsonReport { + return &gojsonReport{ + o: in, + } +} + +func (r *gojsonReport) Fill() error { + // NOTE: could the types.Report include the go package name? + goPkg, err := suitePathToPkg(r.o.SuitePath) + if err != nil { + return err + } + r.goPkg = goPkg + r.elapsed = r.o.RunTime.Seconds() + return nil +} + +// gojsonSpecReport wraps types.SpecReport and calculates extra fields required by gojson +type gojsonSpecReport struct { + o types.SpecReport + // extra calculated fields + testName string + elapsed float64 + action GoJSONAction +} + +func newSpecReport(in types.SpecReport) *gojsonSpecReport { + return &gojsonSpecReport{ + o: in, + } +} + +func (sr *gojsonSpecReport) Fill() error { + sr.elapsed = sr.o.RunTime.Seconds() + sr.testName = createTestName(sr.o) + sr.action = goJSONActionFromSpecState(sr.o.State) + return nil +} + +func suitePathToPkg(dir string) (string, error) { + cfg := &packages.Config{ + Mode: packages.NeedFiles | packages.NeedSyntax, + } + pkgs, err := packages.Load(cfg, dir) + if err != nil { + return "", err + } + if len(pkgs) != 1 { + return "", errors.New("error") + } + return pkgs[0].ID, nil +} + +func createTestName(spec types.SpecReport) string { + name := fmt.Sprintf("[%s]", spec.LeafNodeType) + if spec.FullText() != "" { + name = name + " " + spec.FullText() + } + labels := spec.Labels() + if len(labels) > 0 { + name = name + " [" + strings.Join(labels, ", ") + "]" + } + semVerConstraints := spec.SemVerConstraints() + if len(semVerConstraints) > 0 { + name = name + " [" + strings.Join(semVerConstraints, ", ") + "]" + } + name = strings.TrimSpace(name) + return name +} diff --git a/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson_event_writer.go b/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson_event_writer.go new file mode 100644 index 0000000000..ec5311d069 --- /dev/null +++ b/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson_event_writer.go @@ -0,0 +1,111 @@ +package reporters + +type GoJSONEventWriter struct { + enc encoder + specSystemErrFn specSystemExtractFn + specSystemOutFn specSystemExtractFn +} + +func NewGoJSONEventWriter(enc encoder, errFn specSystemExtractFn, outFn specSystemExtractFn) *GoJSONEventWriter { + return &GoJSONEventWriter{ + enc: enc, + specSystemErrFn: errFn, + specSystemOutFn: outFn, + } +} + +func (r *GoJSONEventWriter) writeEvent(e *gojsonEvent) error { + return r.enc.Encode(e) +} + +func (r *GoJSONEventWriter) WriteSuiteStart(report *gojsonReport) error { + e := &gojsonEvent{ + Time: &report.o.StartTime, + Action: GoJSONStart, + Package: report.goPkg, + Output: nil, + FailedBuild: "", + } + return r.writeEvent(e) +} + +func (r *GoJSONEventWriter) WriteSuiteResult(report *gojsonReport) error { + var action GoJSONAction + switch { + case report.o.PreRunStats.SpecsThatWillRun == 0: + action = GoJSONSkip + case report.o.SuiteSucceeded: + action = GoJSONPass + default: + action = GoJSONFail + } + e := &gojsonEvent{ + Time: &report.o.EndTime, + Action: action, + Package: report.goPkg, + Output: nil, + FailedBuild: "", + Elapsed: ptr(report.elapsed), + } + return r.writeEvent(e) +} + +func (r *GoJSONEventWriter) WriteSpecStart(report *gojsonReport, specReport *gojsonSpecReport) error { + e := &gojsonEvent{ + Time: &specReport.o.StartTime, + Action: GoJSONRun, + Test: specReport.testName, + Package: report.goPkg, + Output: nil, + FailedBuild: "", + } + return r.writeEvent(e) +} + +func (r *GoJSONEventWriter) WriteSpecOut(report *gojsonReport, specReport *gojsonSpecReport) error { + events := []*gojsonEvent{} + + stdErr := r.specSystemErrFn(specReport.o) + if stdErr != "" { + events = append(events, &gojsonEvent{ + Time: &specReport.o.EndTime, + Action: GoJSONOutput, + Test: specReport.testName, + Package: report.goPkg, + Output: ptr(stdErr), + FailedBuild: "", + }) + } + stdOut := r.specSystemOutFn(specReport.o) + if stdOut != "" { + events = append(events, &gojsonEvent{ + Time: &specReport.o.EndTime, + Action: GoJSONOutput, + Test: specReport.testName, + Package: report.goPkg, + Output: ptr(stdOut), + FailedBuild: "", + }) + } + + for _, ev := range events { + err := r.writeEvent(ev) + if err != nil { + return err + } + } + return nil +} + +func (r *GoJSONEventWriter) WriteSpecResult(report *gojsonReport, specReport *gojsonSpecReport) error { + e := &gojsonEvent{ + Time: &specReport.o.EndTime, + Action: specReport.action, + Test: specReport.testName, + Package: report.goPkg, + Elapsed: ptr(specReport.elapsed), + Output: nil, + FailedBuild: "", + } + return r.writeEvent(e) +} diff --git a/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson_reporter.go b/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson_reporter.go new file mode 100644 index 0000000000..633e49b88d --- /dev/null +++ b/vendor/github.com/onsi/ginkgo/v2/internal/reporters/gojson_reporter.go @@ -0,0 +1,45 @@ +package reporters + +import ( + "github.com/onsi/ginkgo/v2/types" +) + +type GoJSONReporter struct { + ev *GoJSONEventWriter +} + +type specSystemExtractFn func (spec types.SpecReport) string + +func NewGoJSONReporter(enc encoder, errFn specSystemExtractFn, outFn specSystemExtractFn) *GoJSONReporter { + return &GoJSONReporter{ + ev: NewGoJSONEventWriter(enc, errFn, outFn), + } +} + +func (r *GoJSONReporter) Write(originalReport types.Report) error { + // suite start events + report := newReport(originalReport) + err := report.Fill() + if err != nil { + return err + } + r.ev.WriteSuiteStart(report) + for _, originalSpecReport := range originalReport.SpecReports { + specReport := newSpecReport(originalSpecReport) + err := specReport.Fill() + if err != nil { + return err + } + if specReport.o.LeafNodeType == types.NodeTypeIt { + // handle any It leaf node as a spec + r.ev.WriteSpecStart(report, specReport) + r.ev.WriteSpecOut(report, specReport) + r.ev.WriteSpecResult(report, specReport) + } else { + // handle any other leaf node as generic output + r.ev.WriteSpecOut(report, specReport) + } + } + r.ev.WriteSuiteResult(report) + return nil +} diff --git a/vendor/github.com/onsi/ginkgo/v2/reporters/gojson_report.go b/vendor/github.com/onsi/ginkgo/v2/reporters/gojson_report.go new file mode 100644 index 0000000000..d02fb7a1ae --- /dev/null +++ b/vendor/github.com/onsi/ginkgo/v2/reporters/gojson_report.go @@ -0,0 +1,61 @@ +package reporters + +import ( + "encoding/json" + "fmt" + "os" + "path" + + "github.com/onsi/ginkgo/v2/internal/reporters" + "github.com/onsi/ginkgo/v2/types" +) + +// GenerateGoTestJSONReport produces a JSON-formatted in the test2json format used by `go test -json` +func GenerateGoTestJSONReport(report types.Report, destination string) error { + // walk report and generate test2json-compatible objects + // JSON-encode the objects into filename + if err := os.MkdirAll(path.Dir(destination), 0770); err != nil { + return err + } + f, err := os.Create(destination) + if err != nil { + return err + } + defer f.Close() + enc := json.NewEncoder(f) + r := reporters.NewGoJSONReporter( + enc, + systemErrForUnstructuredReporters, + systemOutForUnstructuredReporters, + ) + return r.Write(report) +} + +// MergeJSONReports produces a single JSON-formatted report at the passed in destination by merging the JSON-formatted reports provided in sources +// It skips over reports that fail to decode but reports on them via the returned messages []string +func MergeAndCleanupGoTestJSONReports(sources []string, destination string) ([]string, error) { + messages := []string{} + if err := os.MkdirAll(path.Dir(destination), 0770); err != nil { + return messages, err + } + f, err := os.Create(destination) + if err != nil { + return messages, err + } + defer f.Close() + + for _, source := range sources { + data, err := os.ReadFile(source) + if err != nil { + messages = append(messages, fmt.Sprintf("Could not open %s:\n%s", source, err.Error())) + continue + } + _, err = f.Write(data) + if err != nil { + messages = append(messages, fmt.Sprintf("Could not write to %s:\n%s", destination, err.Error())) + continue + } + os.Remove(source) + } + return messages, nil +} diff --git a/vendor/github.com/onsi/ginkgo/v2/reporting_dsl.go b/vendor/github.com/onsi/ginkgo/v2/reporting_dsl.go index 5bf2e62e90..dd135054d4 100644 --- a/vendor/github.com/onsi/ginkgo/v2/reporting_dsl.go +++ b/vendor/github.com/onsi/ginkgo/v2/reporting_dsl.go @@ -165,7 +165,7 @@ ReportAfterSuite nodes must be created at the top-level (i.e. not nested in a Co When running in parallel, Ginkgo ensures that only one of the parallel nodes runs the ReportAfterSuite and that it is passed a report that is aggregated across all parallel nodes -In addition to using ReportAfterSuite to programmatically generate suite reports, you can also generate JSON, JUnit, and Teamcity formatted reports using the --json-report, --junit-report, and --teamcity-report ginkgo CLI flags. +In addition to using ReportAfterSuite to programmatically generate suite reports, you can also generate JSON, GoJSON, JUnit, and Teamcity formatted reports using the --json-report, --gojson-report, --junit-report, and --teamcity-report ginkgo CLI flags. You cannot nest any other Ginkgo nodes within a ReportAfterSuite node's closure. You can learn more about ReportAfterSuite here: https://onsi.github.io/ginkgo/#generating-reports-programmatically @@ -188,6 +188,12 @@ func registerReportAfterSuiteNodeForAutogeneratedReports(reporterConfig types.Re Fail(fmt.Sprintf("Failed to generate JSON report:\n%s", err.Error())) } } + if reporterConfig.GoJSONReport != "" { + err := reporters.GenerateGoTestJSONReport(report, reporterConfig.GoJSONReport) + if err != nil { + Fail(fmt.Sprintf("Failed to generate Go JSON report:\n%s", err.Error())) + } + } if reporterConfig.JUnitReport != "" { err := reporters.GenerateJUnitReport(report, reporterConfig.JUnitReport) if err != nil { @@ -206,6 +212,9 @@ func registerReportAfterSuiteNodeForAutogeneratedReports(reporterConfig types.Re if reporterConfig.JSONReport != "" { flags = append(flags, "--json-report") } + if reporterConfig.GoJSONReport != "" { + flags = append(flags, "--gojson-report") + } if reporterConfig.JUnitReport != "" { flags = append(flags, "--junit-report") } diff --git a/vendor/github.com/onsi/ginkgo/v2/types/config.go b/vendor/github.com/onsi/ginkgo/v2/types/config.go index b99a9e15e9..f847036046 100644 --- a/vendor/github.com/onsi/ginkgo/v2/types/config.go +++ b/vendor/github.com/onsi/ginkgo/v2/types/config.go @@ -96,6 +96,7 @@ type ReporterConfig struct { ForceNewlines bool JSONReport string + GoJSONReport string JUnitReport string TeamcityReport string } @@ -112,7 +113,7 @@ func (rc ReporterConfig) Verbosity() VerbosityLevel { } func (rc ReporterConfig) WillGenerateReport() bool { - return rc.JSONReport != "" || rc.JUnitReport != "" || rc.TeamcityReport != "" + return rc.JSONReport != "" || rc.GoJSONReport != "" || rc.JUnitReport != "" || rc.TeamcityReport != "" } func NewDefaultReporterConfig() ReporterConfig { @@ -359,6 +360,8 @@ var ReporterConfigFlags = GinkgoFlags{ {KeyPath: "R.JSONReport", Name: "json-report", UsageArgument: "filename.json", SectionKey: "output", Usage: "If set, Ginkgo will generate a JSON-formatted test report at the specified location."}, + {KeyPath: "R.GoJSONReport", Name: "gojson-report", UsageArgument: "filename.json", SectionKey: "output", + Usage: "If set, Ginkgo will generate a Go JSON-formatted test report at the specified location."}, {KeyPath: "R.JUnitReport", Name: "junit-report", UsageArgument: "filename.xml", SectionKey: "output", DeprecatedName: "reportFile", DeprecatedDocLink: "improved-reporting-infrastructure", Usage: "If set, Ginkgo will generate a conformant junit test report in the specified file."}, {KeyPath: "R.TeamcityReport", Name: "teamcity-report", UsageArgument: "filename", SectionKey: "output", diff --git a/vendor/github.com/onsi/ginkgo/v2/types/version.go b/vendor/github.com/onsi/ginkgo/v2/types/version.go index 6aca6efa81..a30e68be1a 100644 --- a/vendor/github.com/onsi/ginkgo/v2/types/version.go +++ b/vendor/github.com/onsi/ginkgo/v2/types/version.go @@ -1,3 +1,3 @@ package types -const VERSION = "2.25.3" +const VERSION = "2.26.0" diff --git a/vendor/modules.txt b/vendor/modules.txt index e8db2bfbdc..679e950c9f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -415,7 +415,7 @@ github.com/modern-go/reflect2 # github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 ## explicit github.com/munnerz/goautoneg -# github.com/onsi/ginkgo/v2 v2.25.3 +# github.com/onsi/ginkgo/v2 v2.26.0 ## explicit; go 1.23.0 github.com/onsi/ginkgo/v2 github.com/onsi/ginkgo/v2/config @@ -434,6 +434,7 @@ github.com/onsi/ginkgo/v2/internal github.com/onsi/ginkgo/v2/internal/global github.com/onsi/ginkgo/v2/internal/interrupt_handler github.com/onsi/ginkgo/v2/internal/parallel_support +github.com/onsi/ginkgo/v2/internal/reporters github.com/onsi/ginkgo/v2/internal/testingtproxy github.com/onsi/ginkgo/v2/reporters github.com/onsi/ginkgo/v2/types