我正在尝试像这样运行我的Go测试,并设置一个环境变量:
FOO=BAR go list ./... | grep -v vendor | xargs -n1 go test -timeout=3s
在我的测试中,我做了:
log.Print(os.Getenv("FOO"))
返回一个空字符串。为什么没有设置FOO?
最佳答案
FOO=BAR bash -c 'go list ./... | grep -v vendor | xargs -n1 go test -timeout=3s'
在以下问题的答案中可以找到很好的解释,为什么原始命令不起作用:https://unix.stackexchange.com/questions/134735/environment-variables-are-not-set-when-my-function-is-called-in-a-pipeline
关于go - 为Go测试设置环境变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33471976/