onsi / ginkgo

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

Support for vendoring + modules #559

Closed zmackie closed 3 years ago

zmackie commented 5 years ago

The team I'm on vendors (for reasons...) but we're also using modules. It'd be great if ginkgo's pre-test compile step could respect the existence of this case and run the build with local code (ala go build -mod=vendor. We'd be happy about contributing a PR given a bit of guidance on where to look...

BooleanCat commented 5 years ago

As of ginkgo 1.8.0, you can use ginkgo -mod vendor ...

williammartin commented 5 years ago

Thanks @BooleanCat for the contribution.

@Zanadar Can you check and see if this solves your issue?

zmackie commented 5 years ago

Thanks @booleancat

zmackie commented 5 years ago

@williammartin sure I’ll check. Will re-close if we’re all set.

zmackie commented 5 years ago

@williammartin @BooleanCat I'm not certain this is actually working...it looks like ginkgo is still downloading modules that exist in our local vendor folder

Eg

± dt |develop {17} U:16 ?:68 ✗| → docker run -v $(pwd):/app -it golang:1.12.1 bash
root@d95aa2cffaba:/go# cd /app/
root@d95aa2cffaba:/app# ./scripts/build.sh
++ dirname ./scripts/build.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ GOOS=linux
+ go build -mod=vendor '-ldflags=-s -w' -o bin/supply ./src/nodejs/supply/cli
+ GOOS=linux
+ go build -mod=vendor '-ldflags=-s -w' -o bin/finalize ./src/nodejs/finalize/cli
root@d95aa2cffaba:/app#

(notice modules do not need to be downloaded) vs

root@d95aa2cffaba:/app# ./scripts/unit.sh
++ dirname ./scripts/unit.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ ./scripts/install_tools.sh
++ dirname ./scripts/install_tools.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ go get -u github.com/onsi/ginkgo/ginkgo
go: finding github.com/cloudfoundry/libbuildpack v0.0.0-20190307214535-cd9ee704eaa2
go: finding github.com/tidwall/match v1.0.1
go: finding github.com/hpcloud/tail v1.0.0
go: finding github.com/davecgh/go-spew v1.1.1
go: finding github.com/fsnotify/fsnotify v1.4.7
go: finding golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2
go: finding golang.org/x/text v0.3.0
go: finding gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: finding gopkg.in/yaml.v2 v2.2.1
go: finding cloud.google.com/go v0.34.0
go: finding github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d
go: finding google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2
go: finding github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470
go: finding github.com/shurcooL/notifications v0.0.0-20181007000457-627ab5aea122
go: finding github.com/shurcooL/highlight_diff v0.0.0-20170515013008-09bb4053de1b
go: finding github.com/microcosm-cc/bluemonday v1.0.1
go: finding github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4
go: finding github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1
go: finding gopkg.in/fsnotify.v1 v1.4.7
go: finding github.com/google/go-github v17.0.0+incompatible
go: finding github.com/google/go-cmp v0.2.0
go: finding google.golang.org/api v0.0.0-20181030000543-1d582fd0359e
go: finding github.com/shurcooL/octicon v0.0.0-20181028054416-fa4f57f9efb2
go: finding github.com/shurcooL/gopherjslib v0.0.0-20160914041154-feb6d3990c2c
go: finding github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537
go: finding github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab
go: finding cloud.google.com/go v0.31.0
go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
go: finding github.com/shurcooL/issues v0.0.0-20181008053335-6292fdc1e191
go: finding github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625
go: finding github.com/dustin/go-humanize v1.0.0
go: finding github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568
go: finding github.com/gliderlabs/ssh v0.1.1
go: finding github.com/kr/pretty v0.1.0
go: finding github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48
go: finding github.com/stretchr/testify v1.2.2
go: finding github.com/cloudfoundry/libbuildpack v0.0.0-20181224210246-78d931650f60
go: finding github.com/google/go-querystring v1.0.0
go: finding golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16
go: finding golang.org/x/sys v0.0.0-20181029174526-d69651ed3497
go: finding github.com/shurcooL/gofontwoff v0.0.0-20180329035133-29b52fc0a18d
go: finding github.com/sergi/go-diff v1.0.0
go: finding github.com/google/martian v2.1.0+incompatible
go: finding google.golang.org/grpc v1.16.0
go: finding github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d
go: finding github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
go: finding github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86
go: finding github.com/russross/blackfriday v1.5.2
go: finding github.com/BurntSushi/toml v0.3.1
go: finding golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
go: finding github.com/onsi/ginkgo v1.7.0
go: finding grpc.go4.org v0.0.0-20170609214715-11d0a25b4919
go: finding github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
go: finding github.com/shurcooL/httpgzip v0.0.0-20180522190206-b1c53ac65af9
go: finding github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e
go: finding golang.org/x/net v0.0.0-20181029044818-c44066c5c816
go: finding honnef.co/go/tools v0.0.0-20180728063816-88497007e858
go: finding github.com/shurcooL/issuesapp v0.0.0-20180602232740-048589ce2241
go: finding golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2
go: finding golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52
go: finding github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371
go: finding google.golang.org/appengine v1.2.0
go: finding github.com/kisielk/gotool v1.0.0
go: finding github.com/shurcooL/httperror v0.0.0-20170206035902-86b7830d14cc
go: finding golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852
go: finding dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c
go: finding cloud.google.com/go v0.26.0
go: finding github.com/golang/lint v0.0.0-20180702182130-06c8688daad7
go: finding github.com/shurcooL/htmlg v0.0.0-20170918183704-d01228ac9e50
go: finding github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82
go: finding golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
go: finding sourcegraph.com/sourcegraph/go-diff v0.5.0
go: finding github.com/shurcooL/highlight_go v0.0.0-20181028180052-98c3abbbae20
go: finding github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1
go: finding github.com/googleapis/gax-go v2.0.0+incompatible
go: finding golang.org/x/lint v0.0.0-20180702182130-06c8688daad7
go: finding github.com/kr/pty v1.1.3
go: finding github.com/shurcooL/home v0.0.0-20181020052607-80b7ffcb30f9
go: finding github.com/onsi/ginkgo v1.6.0
go: finding gopkg.in/inf.v0 v0.9.1
go: finding github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041
go: finding dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0
go: finding github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
go: finding github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e
go: finding github.com/pmezard/go-difflib v1.0.0
go: finding github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133
go: finding dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3
go: finding sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4
go: finding golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b
go: finding github.com/golang/mock v1.1.1
go: finding google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8
go: finding github.com/pkg/errors v0.8.1
go: finding gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
go: finding github.com/kr/text v0.1.0
go: finding golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
go: finding gopkg.in/yaml.v2 v2.2.2
go: finding golang.org/x/tools v0.0.0-20190107155254-e063def13b29
go: finding github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239
go: finding go.opencensus.io v0.18.0
go: finding dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412
go: finding github.com/inconshreveable/go-vhost v0.0.0-20160627193104-06d84117953b
go: finding github.com/kr/pty v1.1.1
go: finding github.com/client9/misspell v0.3.4
go: finding golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: finding golang.org/x/net v0.0.0-20180724234803-3673e40ba225
go: finding github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e
go: finding git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999
go: finding github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
go: finding google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf
go: finding google.golang.org/grpc v1.14.0
go: finding google.golang.org/genproto v0.0.0-20180831171423-11092d34479b
go: finding github.com/gogo/protobuf v1.1.1
go: finding github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273
go: finding github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95
go: finding github.com/matttproud/golang_protobuf_extensions v1.0.1
go: finding google.golang.org/appengine v1.1.0
go: finding github.com/ghodss/yaml v1.0.0
go: finding github.com/prometheus/client_golang v0.8.0
go: finding golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4
go: finding github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
go: finding github.com/grpc-ecosystem/grpc-gateway v1.5.0
go: finding github.com/openzipkin/zipkin-go v0.1.1
go: finding github.com/onsi/ginkgo/ginkgo latest
go: downloading github.com/onsi/ginkgo v1.8.0
go: extracting github.com/onsi/ginkgo v1.8.0
go: downloading github.com/hpcloud/tail v1.0.0
go: extracting github.com/hpcloud/tail v1.0.0
go: downloading gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: downloading gopkg.in/fsnotify.v1 v1.4.7
go: extracting gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: extracting gopkg.in/fsnotify.v1 v1.4.7
go: downloading golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6
go: extracting golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6
+ '[' '!' -f .bin/buildpack-packager ']'
+ cd src/nodejs/integration/..
+ ginkgo -mod vendor -r -skipPackage=brats,integration,acceptance
Will skip:
  ./brats
  ./integration
[1553807586] Finalize Suite - 8/8 specs •••••••• SUCCESS! 9.396595ms PASS
[1553807586] Hooks Suite - 15/15 specs ••••••••••••••• SUCCESS! 23.740172ms PASS
[1553807586] Npm Suite - 7/7 specs ••••••• SUCCESS! 6.696297ms PASS
[1553807586] Supply Suite - 108/108 specs •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• SUCCESS! 246.767712ms PASS
[1553807586] Yarn Suite - 10/10 specs •••••••••• SUCCESS! 7.588728ms PASS

Ginkgo ran 5 suites in 32.956562182s
Test Suite Passed
root@d95aa2cffaba:/app#

See go.mod

module github.com/cloudfoundry/nodejs-buildpack

require (
    cloud.google.com/go v0.34.0
    github.com/BurntSushi/toml v0.3.1
    github.com/Dynatrace/libbuildpack-dynatrace v1.2.0
    github.com/Masterminds/semver v1.4.2
    github.com/blang/semver v3.5.1+incompatible
    github.com/cloudfoundry/libbuildpack v0.0.0-20190307214535-cd9ee704eaa2
    github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a
    github.com/golang/mock v1.2.0
    github.com/golang/protobuf v1.2.0
    github.com/google/subcommands v0.0.0-20181012225330-46f0354f6315
    github.com/inconshreveable/go-vhost v0.0.0-20160627193104-06d84117953b
    github.com/onsi/ginkgo v1.8.0
    github.com/onsi/gomega v1.4.3
    github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4
    github.com/tidwall/gjson v1.1.3
    github.com/tidwall/match v1.0.1
    go4.org v0.0.0-20181109185143-00e24f1b2599
    golang.org/x/build v0.0.0-20190107193049-6a02381872d7
    golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc
    golang.org/x/net v0.0.0-20181220203305-927f97764cc3
    golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6
    golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2
    golang.org/x/tools v0.0.0-20190107155254-e063def13b29
    gopkg.in/jarcoal/httpmock.v1 v1.0.0-20181117152235-275e9df93516
    gopkg.in/yaml.v2 v2.2.2
)
zmackie commented 5 years ago

Second confirmation, run after above test run:

root@d95aa2cffaba:/app# ./scripts/unit.sh
++ dirname ./scripts/unit.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ ./scripts/install_tools.sh
++ dirname ./scripts/install_tools.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ go get -u github.com/onsi/ginkgo/ginkgo
go: finding github.com/onsi/ginkgo/ginkgo latest
+ '[' '!' -f .bin/buildpack-packager ']'
+ cd src/nodejs/integration/..
+ ginkgo -mod vendor -r -skipPackage=brats,integration,acceptance
Will skip:
  ./brats
  ./integration
^C
Ginkgo ran 0 suites in 4.274621673s
Test Suite Passed
root@d95aa2cffaba:/app# go clean -modcache
can't load package: package github.com/cloudfoundry/nodejs-buildpack: unknown import path "github.com/cloudfoundry/nodejs-buildpack": cannot find module providing package github.com/cloudfoundry/nodejs-buildpack
root@d95aa2cffaba:/app# ./scripts/unit.sh
++ dirname ./scripts/unit.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ ./scripts/install_tools.sh
++ dirname ./scripts/install_tools.sh
+ cd ./scripts/..
+ source .envrc
+++ pwd
++ export GOBIN=/app/.bin
++ GOBIN=/app/.bin
++ export PATH=/app/.bin:/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
++ PATH=/app/.bin:/app/.bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ go get -u github.com/onsi/ginkgo/ginkgo
go: finding github.com/cloudfoundry/libbuildpack v0.0.0-20190307214535-cd9ee704eaa2
go: finding github.com/Masterminds/semver v1.4.2
go: finding github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a
go: finding github.com/onsi/gomega v1.4.3
go: finding github.com/golang/protobuf v1.2.0
go: finding github.com/tidwall/gjson v1.1.3
go: finding golang.org/x/net v0.0.0-20181220203305-927f97764cc3
go: finding golang.org/x/build v0.0.0-20190107193049-6a02381872d7
go: finding cloud.google.com/go v0.34.0
^C
root@d95aa2cffaba:/app#

(Notice the first time no download, when modcache is primed. Then notice download after cleaning modcache).

46bit commented 5 years ago

I second ginkgo -mod=vendor in Ginkgo v1.8.0 and Go 1.12.4 not using packages from vendor.

williammartin commented 5 years ago

Doh. Seems like we missed something! I'll try to have a look this week but if anyone more familiar with Go modules than me has a good idea, that would be very welcome.

birdayz commented 5 years ago

i'm having the same issue; we're using vendoring for all our deps (go modules are used to define the exact dependencies).

blgm commented 5 years ago

A workaround that I have been using is to run GO111MODULE=on GOFLAGS='-mod=vendor' ginkgo -r

onsi commented 3 years ago

I'm not sure if this i resolved at this point. My mod-fu is weak. I'm going to close this but please reopen if it's still an issue.