【问题标题】:$GOPATH/src/... and vendor/... versions are different$GOPATH/src/... 和 vendor/... 版本不同
【发布时间】:2018-02-01 05:19:42
【问题描述】:

我的项目使用 Go 1.8,依赖于 github.com/stretchr/testify。我使用go get -u github.com/stretchr/testify 检索到最新版本,$GOPATH/src 中的版本似乎是正确的。

我在Gopkg.toml 中添加了最新版本号作为约束:

[[constraint]]
  name = "github.com/stretchr/testify"
  version = "1.1.4"

然后我运行dep ensure -updatedep status 来更新vendor 目录(dep status 的输出):

github.com/stretchr/testify  ^1.1.4  v1.1.4  69483b4  69483b4  1   

$GOPATH/src 中的版本在文件github.com/stretchr/testify/assert/assertions.go 中包含函数PanicsWithValue

func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

但在vendor 的版本中,缺少该功能:

func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

我做错了什么?我想在我的测试中使用函数PanicsWithValue。我什至尝试删除整个vendor 目录并重建它。

【问题讨论】:

  • 没什么。 v1.1.4(最新标签)是从去年九月开始的。 PanicsWithValue 于 6 月 1 日添加。
  • 有没有办法强制dep使用$GOPATH/src中的版本?
  • 我对@9​​87654341@ 不是很熟悉,但它看起来像是全有或全无。您可以完全删除约束 (version = "*"),它应该使用 master@HEAD。
  • 我会试试的。谢谢。
  • 转换为答案。

标签: go versioning vendor


【解决方案1】:

通过将版本固定到 v1.1.4,您明确告诉 dep 使用不包含您想要的功能的版本(查看 GitHub 上的 testify 包的历史 - v1.1.4 是从去年 9 月开始的, PanicsWithValue 于今年 6 月添加)。如果您取消固定版本 (version = "*"),它应该使用包含 PanicsWithValue 的 master@HEAD。

【讨论】:

  • vendor中的版本在dep ensure -update; dep prune; dep status之后仍然不包含PanicsWithValue函数。
  • 在更新Gopkg.toml 文件后您是否运行dep ensure
  • dep statustestify 的输出是什么?
  • github.com/stretchr/testify * v1.1.4 69483b4 69483b4 1
  • 我的约束包含:[[constraint]] name = "github.com/stretchr/testify" version = "*"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 2015-10-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多