英文:
How to Import https://github.com/go-test/deep into Your Golang Test
问题
我是你的中文翻译助手,以下是翻译好的内容:
我对Golang还不熟悉。
我的go版本是1.17.8。
我正在尝试编写测试来比较结构体。
我找到了一个名为这个的库,可以显示出哪些字段是完全相等的。
所以我想使用它来替代reflect.DeepEqual。
这是我的测试go文件:
package main
import (
"os"
"testing"
"github.com/go-test/deep"
)
func TestDeepEqual(t *testing.T) {
os.Remove("_decktesting.txt")
d := newDeck()
d.saveToFile("_decktesting.txt")
l := newDeckFromFile("_decktesting.txt")
if diff := deep.Equal(d, l); diff != nil {
t.Error(diff)
}
}
当我尝试进行测试时,它显示如下:
➜ go get
go-training/cards on develop [!] via 🐹 v1.17.8
➜ go test
# go-training/cards
deck_test.go:7:2: cannot find package "github.com/go-test/deep" in any of:
/usr/local/go/src/github.com/go-test/deep (from $GOROOT)
/Users/ssamarasin/go/src/github.com/go-test/deep (from $GOPATH)
FAIL go-training/cards [setup failed]
go-training/cards on develop [!] via 🐹 v1.17.8
➜ go install github.com/go-test/deep@latest
package github.com/go-test/deep is not a main package
有人可以解释一下我如何使用这个库来比较我的结构体吗?
谢谢
英文:
I'm new to Golang.
My go version: 1.17.8
Trying write tests to compare strcuts.
Found this lib can show you which fields exactly equivalent.
So thought of using it over reflect.DeepEqual
Here's my test go file,
package main
import (
"os"
"testing"
"github.com/go-test/deep"
)
func TestDeepEqual(t *testing.T) {
os.Remove("_decktesting.txt")
d := newDeck()
d.saveToFile("_decktesting.txt")
l := newDeckFromFile("_decktesting.txt")
if diff := deep.Equal(d, l); diff != nil {
t.Error(diff)
}
}
Here's what it says when try to test,
➜ go get
go-training/cards on develop [!] via 🐹 v1.17.8
➜ go test
# go-training/cards
deck_test.go:7:2: cannot find package "github.com/go-test/deep" in any of:
/usr/local/go/src/github.com/go-test/deep (from $GOROOT)
/Users/ssamarasin/go/src/github.com/go-test/deep (from $GOPATH)
FAIL go-training/cards [setup failed]
go-training/cards on develop [!] via 🐹 v1.17.8
➜ go install github.com/go-test/deep@latest
package github.com/go-test/deep is not a main package
Can someone please explain how I can use this lib to compare my structs?
Thank you
答案1
得分: 1
GO111MODULE=on go get github.com/go-test/deep
英文:
GO111MODULE=on go get github.com/go-test/deep
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论