feat(Go-StudyExample):2021/02/09:新增merge源码阅读和单测代码
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package mergo_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
type document struct {
|
||||
Created *time.Time
|
||||
}
|
||||
|
||||
func TestIssue23MergeWithOverwrite(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := document{
|
||||
&now,
|
||||
}
|
||||
expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
src := document{
|
||||
&expected,
|
||||
}
|
||||
|
||||
if err := mergo.MergeWithOverwrite(&dst, src); err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
|
||||
if !dst.Created.Equal(*src.Created) { //--> https://golang.org/pkg/time/#pkg-overview
|
||||
t.Errorf("Created not merged in properly: dst.Created(%v) != src.Created(%v)", dst.Created, src.Created)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user