feat(Go-StudyExample):2021/02/09:新增merge源码阅读和单测代码

This commit is contained in:
Huangzj
2021-02-09 16:00:31 +08:00
parent 05f55b0eac
commit cf02f0bf10
51 changed files with 3712 additions and 1 deletions
@@ -0,0 +1,39 @@
package mergo_test
import (
"testing"
"github.com/imdario/mergo"
)
type user struct {
Name string
}
type token struct {
User *user
Token *string
}
func TestIssue149(t *testing.T) {
dest := &token{
User: &user{
Name: "destination",
},
Token: nil,
}
tokenValue := "Issue149"
src := &token{
User: nil,
Token: &tokenValue,
}
if err := mergo.Merge(dest, src, mergo.WithOverwriteWithEmptyValue); err != nil {
t.Error(err)
}
if dest.User != nil {
t.Errorf("expected nil User, got %q", dest.User)
}
if dest.Token == nil {
t.Errorf("expected not nil Token, got %q", *dest.Token)
}
}