onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.38k stars 660 forks source link

Precompiled Suites don't have build information #1440

Closed lucacome closed 3 months ago

lucacome commented 3 months ago

I'd like to be able to read build information from the code. Since go 1.18 it's possible to get vcs data with runtime/debug, see https://pkg.go.dev/runtime/debug#BuildSetting

But the suite doesn't seem to contain any data

❯ go version -m suite/suite.test
suite/suite.test: go1.22.5

As an example

❯ go version -m ginkgo
ginkgo: go1.22.5
    path    github.com/onsi/ginkgo/v2/ginkgo
    mod github.com/onsi/ginkgo/v2   (devel)
    dep github.com/go-task/slim-sprig/v3    v3.0.0  h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
    dep github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6  h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg=
    dep golang.org/x/tools  v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
    build   -buildmode=exe
    build   -compiler=gc
    build   DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
    build   CGO_ENABLED=1
    build   CGO_CFLAGS=
    build   CGO_CPPFLAGS=
    build   CGO_CXXFLAGS=
    build   CGO_LDFLAGS=
    build   GOARCH=arm64
    build   GOOS=darwin
    build   vcs=git
    build   vcs.revision=b69c00d4ce8b2d0bb408b8cf6dc3317e6a9deeb1
    build   vcs.time=2024-06-15T21:36:40Z
    build   vcs.modified=false
onsi commented 3 months ago

ginkgo build is just using go test -c under the hood. is there a flag it should be passing that it isn't?

lucacome commented 3 months ago

You need to add -buildvcs=true

lucacome commented 3 months ago

Looks like there's a bug in go (https://github.com/golang/go/issues/33976) and the package needs to be called main, that's why there wasn't any information at all for me, now I have:

❯ go version -m suite/suite.test
suite/suite.test: go1.22.5
    path    github.com/nginxinc/nginx-gateway-fabric/tests/suite
    mod github.com/nginxinc/nginx-gateway-fabric/tests  (devel)
    build   -buildmode=exe
    build   -compiler=gc
    build   CGO_ENABLED=1
    build   CGO_CFLAGS=
    build   CGO_CPPFLAGS=
    build   CGO_CXXFLAGS=
    build   CGO_LDFLAGS=
    build   GOARCH=arm64
    build   GOOS=darwin

but yeah it's still missing the vcs info.

I confirmed that adding -buildvcs=true to ginkgo will add that info. I might try to open a PR.