Skip to content

cmd/go: mod vendor tries to evaluate go:embed pattern inside _test.go files #63473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wizardishungry opened this issue Oct 9, 2023 · 6 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wizardishungry
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.21.1 darwin/arm64

Does this issue reproduce with the latest release?

I don't know.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/jon/Library/Caches/go-build'
GOENV='/Users/jon/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/jon/.asdf/installs/golang/1.21.1/packages/pkg/mod'
GONOPROXY='bitbucket.org/thetalake'
GONOSUMDB='bitbucket.org/thetalake'
GOOS='darwin'
GOPATH='/Users/jon/.asdf/installs/golang/1.21.1/packages'
GOPRIVATE='bitbucket.org/thetalake'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/jon/.asdf/installs/golang/1.21.1/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/jon/.asdf/installs/golang/1.21.1/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/jon/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/4y/nhc3l04n53x2125plghk78bw0000gp/T/go-build3701474416=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

  1. Import a package containing go:embed directives inside a _test.go file.
import _ "github.com/emiago/sipgo"

For example, https://github.com/emiago/sipgo/blob/main/server_integration_test.go#L26 contains go:embed directives that will not satisfied.

  1. Run go mod vendor:

What did you expect to see?

go mod vendor completes normally

What did you see instead?

go: pattern testdata/certs/client.crt: no matching files found
@seankhliao

This comment was marked as outdated.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2023
@wizardishungry

This comment was marked as resolved.

@seankhliao
Copy link
Member

Sorry, I misremembered.

cc @bcmills

@seankhliao seankhliao reopened this Oct 9, 2023
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Oct 9, 2023
@quantonganh
Copy link
Contributor

quantonganh commented Oct 10, 2023

So, according to the go help mod vendor:

$ go help mod vendor
usage: go mod vendor [-e] [-v] [-o outdir]

Vendor resets the main module's vendor directory to include all packages
needed to build and test all the main module's packages.
It does not include test code for vendored packages.

We should not include embed patterns in test files when vendoring? cc @matloob

quantonganh added a commit to quantonganh/go that referenced this issue Oct 11, 2023
Currently, `go mod vendor` copy all files matched by //go:embed, even when it is in a _test.go file.
According to the documentation, it should not include test code for vendored packages.

Fixes golang#63473
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/534495 mentions this issue: modcmd: do not copy test embed files when vendoring

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/534376 mentions this issue: modcmd: do not copy test embed files when vendoring

@bcmills bcmills added this to the Go1.22 milestone Oct 13, 2023
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 13, 2023
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 13, 2023
yunginnanet pushed a commit to yunginnanet/go that referenced this issue Oct 20, 2023
Currently, go mod vendor copy all files matched by //go:embed,
even when it is in a _test.go file. According to the documentation,
it should not include test code for vendored packages.

Fixes golang#63473

Change-Id: I28c411724fc7b7aeb683857fc114e20b08635e01
Reviewed-on: https://go-review.googlesource.com/c/go/+/534376
Auto-Submit: Cuong Manh Le <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Cuong Manh Le <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
@golang golang locked and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants