为什么 goapp test 在 /tmp 目录中查找文件?

huangapple go评论87阅读模式
英文:

Why is goapp test is looking for files in /tmp?

问题

我正在尝试在我的本地开发机上使测试工作。Cloud SDK 版本为:159.0.0。

根据我所阅读的所有内容,都说我不应该更改 GOROOT,所以我不确定如何解决这个问题。

$ /Users/bryan/google-cloud-sdk/platform/google_appengine/goroot/bin/goapp test

go: 无法找到 GOROOT 目录:/tmp/go_sdk887571938/appengine/go_appengine/goroot

bryan@Bryans-MacBook Thu Jun 15 10:22:37 ~/go/src/skincarereview

$ 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"

bryan@Bryans-MacBook Thu Jun 15 10:22:57 ~/go/src/skincarereview

$ ls ~/google-cloud-sdk

总计 408
drwxr-xr-x  30 bryan  staff    1020 Jun 14 20:31 .install
-rw-r--r--   1 bryan  staff     980 Jun 14 20:30 LICENSE
-rw-r--r--   1 bryan  staff     673 Jun 14 20:30 README
-rw-r--r--   1 bryan  staff  162673 Jun 14 20:30 RELEASE_NOTES
-rw-r--r--   1 bryan  staff       8 Jun 14 20:30 VERSION
drwxr-xr-x  10 bryan  staff     340 Jun 14 20:30 bin
-rw-r--r--   1 bryan  staff    2734 Jun 14 20:30 completion.bash.inc
-rw-r--r--   1 bryan  staff    2083 Jun 14 20:30 completion.zsh.inc
drwxr-xr-x   3 bryan  staff     102 Jun 14 20:30 help
-rwxr-xr-x   1 bryan  staff    1581 Jun 14 20:30 install.bat
-rwxr-xr-x   1 bryan  staff    3471 Jun 14 20:30 install.sh
drwxr-xr-x  10 bryan  staff     340 Jun 14 20:30 lib
-rw-r--r--   1 bryan  staff     308 Jun 14 20:30 path.bash.inc
-rw-r--r--   1 bryan  staff    1210 Jun 14 20:30 path.fish.inc
-rw-r--r--   1 bryan  staff      31 Jun 14 20:30 path.zsh.inc
drwxr-xr-x   6 bryan  staff     204 Jun 14 20:30 platform
-rw-r--r--   1 bryan  staff      40 Jun 14 20:30 properties

bryan@Bryans-MacBook Thu Jun 15 10:24:22 ~/go/src/skincarereview

$ find / -name goroot 2>/dev/null

/Users/bryan/google-cloud-sdk/platform/google_appengine/goroot

bryan@Bryans-MacBook Thu Jun 15 10:28:43 ~/go/src/skincarereview

$ echo $PATH

/Users/bryan/google-cloud-sdk/bin:/Users/bryan/go/src/:/Users/bryan/google-cloud-sdk/platform/google_appengine/goroot/bin/:/Users/bryan/google-cloud-sdk/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin

查看 main.go 的第 155 行,我认为错误是在那里抛出的,我没有看到设置 "goroot" 的地方。

if fi, err := os.Stat(goroot); err != nil || !fi.IsDir() {
	fmt.Fprintf(os.Stderr, "go: 无法找到 GOROOT 目录:%v\n", goroot)
	os.Exit(2)
}
英文:

I'm trying to get tests working on my local dev machine Cloud SDK version is: 159.0.0

Everything I've read says that I should no change GOROOT so I'm not sure how to fix this.

$ /Users/bryan/google-cloud-sdk/platform/google_appengine/goroot/bin/goapp test

go: cannot find GOROOT directory: /tmp/go_sdk887571938/appengine/go_appengine/goroot

bryan@Bryans-MacBook Thu Jun 15 10:22:37 ~/go/src/skincarereview

$ 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"

bryan@Bryans-MacBook Thu Jun 15 10:22:57 ~/go/src/skincarereview

$ ls ~/google-cloud-sdk

total 408
drwxr-xr-x  30 bryan  staff    1020 Jun 14 20:31 .install
-rw-r--r--   1 bryan  staff     980 Jun 14 20:30 LICENSE
-rw-r--r--   1 bryan  staff     673 Jun 14 20:30 README
-rw-r--r--   1 bryan  staff  162673 Jun 14 20:30 RELEASE_NOTES
-rw-r--r--   1 bryan  staff       8 Jun 14 20:30 VERSION
drwxr-xr-x  10 bryan  staff     340 Jun 14 20:30 bin
-rw-r--r--   1 bryan  staff    2734 Jun 14 20:30 completion.bash.inc
-rw-r--r--   1 bryan  staff    2083 Jun 14 20:30 completion.zsh.inc
drwxr-xr-x   3 bryan  staff     102 Jun 14 20:30 help
-rwxr-xr-x   1 bryan  staff    1581 Jun 14 20:30 install.bat
-rwxr-xr-x   1 bryan  staff    3471 Jun 14 20:30 install.sh
drwxr-xr-x  10 bryan  staff     340 Jun 14 20:30 lib
-rw-r--r--   1 bryan  staff     308 Jun 14 20:30 path.bash.inc
-rw-r--r--   1 bryan  staff    1210 Jun 14 20:30 path.fish.inc
-rw-r--r--   1 bryan  staff      31 Jun 14 20:30 path.zsh.inc
drwxr-xr-x   6 bryan  staff     204 Jun 14 20:30 platform
-rw-r--r--   1 bryan  staff      40 Jun 14 20:30 properties

bryan@Bryans-MacBook Thu Jun 15 10:24:22 ~/go/src/skincarereview

$ find / -name goroot 2>/dev/null

/Users/bryan/google-cloud-sdk/platform/google_appengine/goroot

bryan@Bryans-MacBook Thu Jun 15 10:28:43 ~/go/src/skincarereview

$ echo $PATH

/Users/bryan/google-cloud-sdk/bin:/Users/bryan/go/src/:/Users/bryan/google-cloud-sdk/platform/google_appengine/goroot/bin/:/Users/bryan/google-cloud-sdk/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin

Looking at main.go line 155, where I think the error is being thrown, I don't see where "goroot" is being set .

if fi, err := os.Stat(goroot); err != nil || !fi.IsDir() {
	fmt.Fprintf(os.Stderr, "go: cannot find GOROOT directory: %v\n", goroot)
	os.Exit(2)
}

答案1

得分: 1

你可能想要了解一下go run/test的工作原理。该程序基本上会构建到一个临时位置,然后运行,所以这可能是为什么它会抱怨你的goroot的原因。

这个问题可能会对你有所帮助:https://stackoverflow.com/questions/23847003/golang-tests-and-working-directory

英文:

You might want to read up on how go run/test works. The program basically builds into a temporary location and then runs, so that might be why it's complaining about your goroot.

This question could possibly help you: https://stackoverflow.com/questions/23847003/golang-tests-and-working-directory

答案2

得分: 1

你可以尝试按照这个答案的建议进行操作:

> 如果你的安装出现了严重问题(我曾经遇到过这种情况),只需删除云SDK及其在$PATH中的任何引用。还要完全卸载常规的Go安装。
>
> 然后从头开始。安装Go,解压google-cloud-sdk,运行安装程序(如果需要,将其添加到$PATH),gcloud components install app-engine-go
完成。

正如同样的答案中提到的,你不需要在任何地方设置GOROOT它会为你设置

英文:

You can try and follow the recommendation of this answer:

> If your install is messed up beyond reason (happened to me once), just remove the cloud SDK and any references to it in your $PATH. Also completely uninstall the regular Go installation.
>
> Then start from scratch. Install Go, unpack google-cloud-sdk, run installer (add to $PATH if needed), gcloud components install app-engine-go.
Voila.

As mentioned in that same answer, you don't set GOROOT anywhere, it is set for you.

答案3

得分: 0

我相信你正在调用错误的goapp。你应该调用位于google_appengine文件夹中的goapp,如下所示:

/Users/bryan/google-cloud-sdk/platform/google_appengine/goapp test

如果由于某种原因你在google_appengine中没有goapp,我会感到非常惊讶,但以下方法也可以工作。(仍然以上述方式调用是正确的。goapp将appengine的goroot解析为相对路径,所以goapp本身的位置很重要。)

GOROOT=/Users/bryan/google-cloud-sdk/platform/google_appengine/goroot /Users/bryan/google-cloud-sdk/platform/google_appengine/goapp test
英文:

I believe you are calling wrong goapp. You should be calling one that is directly in google_appengine folder as follows:

/Users/bryan/google-cloud-sdk/platform/google_appengine/goapp test

If you don't have goapp in google_appengine for some reason, I'll be quite surprised, but then following should work too. (Still the above is the correct way of calling it. goapp resolves appengine's goroot as a relative path from it's own location, so it's important where goapp itself is located.)

GOROOT=/Users/bryan/google-cloud-sdk/platform/google_appengine/goroot /Users/bryan/google-cloud-sdk/platform/google_appengine/goapp test

huangapple
  • 本文由 发表于 2017年6月16日 22:56:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/44592333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定