英文:
Why "go test -v" doesn't see the GOPATH or GOPATH but "go env" does?
问题
应用程序在本地运行时正常工作:
$ dev_appserver.py app.yaml
然而,当我尝试运行测试时,环境似乎没有设置。
$ go test -v
skincare.go:6:5: 找不到任何包“appengine”:
/usr/local/go/src/appengine(来自$GOROOT)
/Users/bryan/go/src/appengine(来自$GOPATH)
skincare.go:7:5: 找不到任何包“appengine/datastore”:
/usr/local/go/src/appengine/datastore(来自$GOROOT)
/Users/bryan/go/src/appengine/datastore(来自$GOPATH)
skincare.go:8:5: 找不到任何包“appengine/user”:
/usr/local/go/src/appengine/user(来自$GOROOT)
/Users/bryan/go/src/appengine/user(来自$GOPATH)
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bryan/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
英文:
The application works fine when I run it locally with:
$ dev_appserver.py app.yaml
However, when I attempt to run tests, the ENV doesn't seem to be set.
$ go test -v
skincare.go:6:5: cannot find package "appengine" in any of:
/usr/local/go/src/appengine (from $GOROOT)
/Users/bryan/go/src/appengine (from $GOPATH)
skincare.go:7:5: cannot find package "appengine/datastore" in any of:
/usr/local/go/src/appengine/datastore (from $GOROOT)
/Users/bryan/go/src/appengine/datastore (from $GOPATH)
skincare.go:8:5: cannot find package "appengine/user" in any of:
/usr/local/go/src/appengine/user (from $GOROOT)
/Users/bryan/go/src/appengine/user (from $GOPATH)
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bryan/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
答案1
得分: 3
$GOPATH
不应包含路径中的 src
部分。因此,应该将其指向 /Users/bryan/go
,而不是 /Users/bryan/go/src/
。
英文:
$GOPATH
should not not contain the src
part of the path. So instead of pointing to /Users/bryan/go/src/
it should point to /Users/bryan/go
.
答案2
得分: 0
我怀疑你的测试失败是因为你直接使用go test
来调用它们,而不是使用App Engine SDK的测试运行器goapp test
,后者在运行时会将你链接到appengine包。
英文:
I suspect your tests are failing because you're invoking them directly with go test
rather than using the App Engine SDK's test runner, goapp test
, which will link you to the appengine package when it runs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论