我在 http://github.com/NeilGarb/budget 设置了一个公共(public) golang 项目,带有子包 core 和 api。我将项目保存在 $GOPATH/src/github.com/NeilGarb/budget 中。
我想使用 Travis CI 运行 core 的 ginkgo 测试,但我在我的测试包中使用了绝对导入,Travis 提示它找不到所述包。
例如我的测试包括:
package user_test
import (
. "github.com/NeilGarb/budget/core"
)
在我的本地机器上运行 ant 运行良好,但是当 travis 尝试运行测试时我得到:
core-test:
[exec] Failed to compile core:
[exec]
[exec] can't load package: package github.com/NeilGarb/budget/core: cannot find package "github.com/NeilGarb/budget/core" in any of:
[exec] /home/travis/.gvm/gos/go1.2/src/pkg/github.com/NeilGarb/budget/core (from $GOROOT)
[exec] /home/travis/.gvm/pkgsets/go1.2/global/src/github.com/NeilGarb/budget/core (from $GOPATH)
[exec]
[exec] Ginkgo ran in 714.967041ms
[exec] Test Suite Failed
我尝试在我的测试中使用相对导入(即“../core”),这很有效,但我的覆盖率总是显示 0%。
要做什么? :(
最佳答案
我通过构建从 $GOPATH/src/github.com/NeilGarb/budget 到 $TRAVIS_BUILD_DIR 的符号链接(symbolic link)解决了这个问题。
关于去绝对进口和Travis CI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22560778/