0

我已经分叉了 hyperledger/fabric 项目,在我的 repo 中,我尝试使用以下命令运行 ECA 的单元测试:但是我收到以下错误:

vagrant@hyperledger-devenv:v0.0.10-37b6688:/opt/gopath/src/github.com/hyperledger/fabric/membersrvc/ca$ go test eca_test.go
command-line-arguments
eca_test.go:30:2: 不能在以下任何一个中找到包“command-/vendor /github.com/golang/protobuf/proto”:/opt/go/src/command-/vendor /github.com/golang/protobuf/proto(来自 $GOROOT)
/ opt /gopath/src/ command-/vendor /github.com/golang/protobuf/proto (来自 $GOPATH) FAIL command-line-arguments [设置失败]

同样,当我尝试运行 CA 单元测试时出现以下错误:

vagrant@hyperledger-devenv:v0.0.10-37b6688:/opt/gopath/src/github.com/hyperledger/fabric/membersrvc/ca$ go test ca_test.go
command-line-arguments
ca_test.go:28:2: 不能在以下任何一个中找到包“command-/vendor/github.com/spf13/viper”:/opt/go/src/command-/vendor/github.com/spf13/viper(来自 $GOROOT)
/opt/gopath/src /command-/vendor/github.com/spf13/viper(来自 >$GOPATH)
FAIL 命令行参数 [设置失败]

几天前这些曾经为我工作,但是在我用超级账本/项目的最新更改更新了我的分叉后,我无法运行测试

这是我的 GOPATH 的值:

vagrant@hyperledger-devenv:v0.0.10-37b6688:/opt/gopath/src/github.com/hyperledger/fabric$ echo $GOPATH /opt/gopath

我不确定为什么 golang 构建系统在查找导入的包时会将“command-/vendor”附加到路径中。有人可以帮我解决这个问题吗?

4

1 回答 1

1

根据文档go test期望包名称作为参数。go test .如果您运行并执行此包的所有测试,则测试应该没有问题。

它可以运行go test eca_test.go,但在这种情况下,您必须指定构建“eca_test”所需的所有其他文件。有关详细信息,请参阅“如何在指定文件中运行测试用例? ”。

如果您只想从这个包中运行一个测试,最好使用go test . -run TestNewECA “TestNewECA”是 eca_test.go 中测试函数的名称,而不是文件名。

于 2016-07-04T15:06:28.050 回答