Skip to content
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

go test is looking for packages in /go/src instead of /go/pkg :( #38758

Closed
ORESoftware opened this issue Apr 30, 2020 · 8 comments
Closed

go test is looking for packages in /go/src instead of /go/pkg :( #38758

ORESoftware opened this issue Apr 30, 2020 · 8 comments

Comments

@ORESoftware
Copy link

ORESoftware commented Apr 30, 2020

I am on:

go version go1.13.8 linux/amd64

I have this set:

export GO111MODULE='auto'
export GOPROXY='direct'
export GOSUMDB='off'

I run this:

go test -v -timeout 6000s "$some_dir_which_is_a_pkg" 

and I get this :(

/go/src/github.com/cm/cm-go-api/database/database.go:18:2: cannot find package "gopkg.in/mgo.v2" in any of:
        /usr/local/go/src/gopkg.in/mgo.v2 (from $GOROOT)
        /go/src/gopkg.in/mgo.v2 (from $GOPATH)
/go/src/github.com/cm/cm-go-api/v3/common/user.go:20:2: cannot find package "gopkg.in/mgo.v2/bson" in any of:
        /usr/local/go/src/gopkg.in/mgo.v2/bson (from $GOROOT)
        /go/src/gopkg.in/mgo.v2/bson (from $GOPATH)
/go/src/github.com/cm/cm-go-api/database/database.go:19:2: cannot find package "gopkg.in/zabawaba99/firego.v1" in any of:
        /usr/local/go/src/gopkg.in/zabawaba99/firego.v1 (from $GOROOT)
        /go/src/gopkg.in/zabawaba99/firego.v1 (from $GOPATH)
✗✗✗✗✗✗ Test for package '/go/src/github.com/cm/cm-go-api/v3/organization/tags' has failed. ✗✗✗✗✗✗

To me it appears that go test is looking for packages/source in $GOPATH/src instead of $GOPATH/pkg. Why?

@ORESoftware
Copy link
Author

ORESoftware commented Apr 30, 2020

I tried this:

export GOPATH="$GOPATH:$GOPATH/pkg/mod"

and it didn't really help :( but at least it's looking in the new dir:

/go/src/github.com/cm/cm-go-api/v3/model/boil_queries.go:7:2: cannot find package "github.com/volatiletech/sqlboiler/drivers" in any of:
        /usr/local/go/src/github.com/volatiletech/sqlboiler/drivers (from $GOROOT)
        /go/src/github.com/volatiletech/sqlboiler/drivers (from $GOPATH)
        /go/pkg/mod/src/github.com/volatiletech/sqlboiler/drivers
/go/src/github.com/cm/cm-go-api/v3/model/advances.go:21:2: cannot find package "github.com/volatiletech/sqlboiler/queries" in any of:
        /usr/local/go/src/github.com/volatiletech/sqlboiler/queries (from $GOROOT)
        /go/src/github.com/volatiletech/sqlboiler/queries (from $GOPATH)
        /go/pkg/mod/src/github.com/volatiletech/sqlboiler/queries
/go/src/github.com/cm/cm-go-api/v3/model/advances.go:22:2: cannot find package "github.com/volatiletech/sqlboiler/queries/qm" in any of:
        /usr/local/go/src/github.com/volatiletech/sqlboiler/queries/qm (from $GOROOT)
        /go/src/github.com/volatiletech/sqlboiler/queries/qm (from $GOPATH)
        /go/pkg/mod/src/github.com/volatiletech/sqlboiler/queries/qm

@ORESoftware
Copy link
Author

ORESoftware commented Apr 30, 2020

ok so part of the problem is that the path turns out to be:

  /go/pkg/mod/src/golang.org/x/oauth2
 ~~~~~~~~~~~~~^^^~~~~~~~~~~~~~~~

instead of the desired:

  /go/pkg/mod/golang.org/x/oauth2

so it's appending a src folder, when I don't intend for it to append a src folder. that's a problem I guess, when you want to explicitly add something to the path, without adding a src folder I guess lol fml. But I doubt adding $GOPATH/pkg/mod to the GOPATH is desired behavior anyway, so I am unsure of how to proceed

@bcmills
Copy link
Contributor

bcmills commented Apr 30, 2020

Please fill out the complete issue template. (The requested go env output is relevant here.)

The fact that the error message indicates directories in GOPATH suggests that you are running in GOPATH mode instead of module mode. pkg/mod is only used in module mode. (See go help modules.)

@bcmills bcmills closed this as completed Apr 30, 2020
@ORESoftware
Copy link
Author

ORESoftware commented Apr 30, 2020

I tried this too:

export GO111MODULE='on'

is there a different env var I need to set? go help modules is not helping, if there is a link online that answers the question that would help. I am in a dockerfile, all go env vars are as defaulted, except for the 3 env vars aforementioned.

@ORESoftware
Copy link
Author

Here is the go env output:

GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go:/go/pkg/mod"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build459888442=/tmp/go-build -gno-record-gcc-switches"

@bcmills
Copy link
Contributor

bcmills commented Apr 30, 2020

Sorry, but at this point we only use the Go issue tracker for tracking defects in the Go compiler and toolchain, not for answering usage questions.

Especially without the go env output and a specific set of commands (and ideally source files) to reproduce the problem, this does not look like a defect in cmd/go.

The Using Go Modules blog post might be a good place for you to start. (Note in particular that the current working directory for the go command must be within the main module.)

There are many other methods to get help if you're still looking for answers:

Thanks

@ORESoftware
Copy link
Author

np, so fwiw setting these explicitly worked:

export GO111MODULE='on'
unset GOPROXY
unset GOSUMDB

my guess is that

export GO111MODULE='auto'

was not working, but I lost track of wtf was happening, now that it works, I gotta move on to other stuff

@JeanTekk
Copy link

JeanTekk commented Feb 26, 2021

Same issue on Windows main.go:8:2: cannot find package "github.com/julienschmidt/httprouter" in any of: C:\sdk\Go\src\github.com\julienschmidt\httprouter (from $GOROOT) C:\Users\<user>\go\src\github.com\julienschmidt\httprouter (from $GOPATH)
go env
set GO111MODULE=auto set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\<user>\AppData\Local\go-build set GOENV=C:\Users\<user>\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\<user>\go\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=C:\Users\<user>\go set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\sdk\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\sdk\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.16 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD= set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\<user>\AppData\Local\Temp\go-build2198367264=/tmp/go-build -gno-record-gcc-switches

EDIT:
This issue came with installing "go1.16.windows-amd64.msi" returning to "go1.15.6.windows-amd64.msi" solved the issue.

@golang golang locked and limited conversation to collaborators Feb 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants