Golang:测试和工作目录
我正在为Go中的应用程序编写一些单元测试。但是测试失败,因为它找不到配置文件。通常情况下,二进制文件会在工作目录下的 conf / *。conf
中查找配置文件。
I'm writing some unit tests for my application in Go. The tests fail however because it cannot find the configuration files. Normally the binary looks for the configuration files in the working directory under the path conf/*.conf
.
I认为浏览到 conf /
并运行 go test
的目录会解决它,但它仍然会报告文件系统找不到指定的路径。
I figured that browsing to the directory that has conf/
and running go test
in it would solve it, but it still reports that the file system cannot find the path specified.
如何告诉 go test
使用某个目录作为工作目录,以便测试可能实际执行?
How can I tell go test
to use a certain directory as the working directory so that the tests may actually be executed?
我不相信这是可能的。我一直无法找到明确说明这一点的文档,但我相信 go test
总是使用软件包目录(包含go源文件)作为工作目录。
I do not believe this is possible. I have not been able to find documentation stating this explicitly, but I believe go test
always uses the package directory (containing the go source files) as the working directory.