Package list golang-github-imdario-mergo / 47853799-ea8e-48db-ae84-6f8bdbd2f952/main issue38_test.go
47853799-ea8e-48db-ae84-6f8bdbd2f952/main

Tree @47853799-ea8e-48db-ae84-6f8bdbd2f952/main (Download .tar.gz)

issue38_test.go @47853799-ea8e-48db-ae84-6f8bdbd2f952/main

f0c9309
6720d30
 
 
 
f0c9309
 
6720d30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0c9309
 
6720d30
 
f0c9309
6720d30
f0c9309
6720d30
 
 
 
 
 
 
 
 
 
f0c9309
 
6720d30
 
f0c9309
6720d30
f0c9309
6720d30
 
 
 
 
 
 
 
 
 
 
 
f0c9309
 
6720d30
 
f0c9309
6720d30
f0c9309
6720d30
 
package mergo_test

import (
	"testing"
	"time"

	"github.com/imdario/mergo"
)

type structWithoutTimePointer struct {
	Created time.Time
}

func TestIssue38Merge(t *testing.T) {
	dst := structWithoutTimePointer{
		time.Now(),
	}

	expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	src := structWithoutTimePointer{
		expected,
	}

	if err := mergo.Merge(&dst, src); err != nil {
		t.Errorf("Error while merging %s", err)
	}

	if dst.Created == src.Created {
		t.Errorf("Created merged unexpectedly: dst.Created(%v) == src.Created(%v)", dst.Created, src.Created)
	}
}

func TestIssue38MergeEmptyStruct(t *testing.T) {
	dst := structWithoutTimePointer{}

	expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	src := structWithoutTimePointer{
		expected,
	}

	if err := mergo.Merge(&dst, src); err != nil {
		t.Errorf("Error while merging %s", err)
	}

	if dst.Created == src.Created {
		t.Errorf("Created merged unexpectedly: dst.Created(%v) == src.Created(%v)", dst.Created, src.Created)
	}
}

func TestIssue38MergeWithOverwrite(t *testing.T) {
	dst := structWithoutTimePointer{
		time.Now(),
	}

	expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	src := structWithoutTimePointer{
		expected,
	}

	if err := mergo.MergeWithOverwrite(&dst, src); err != nil {
		t.Errorf("Error while merging %s", err)
	}

	if dst.Created != src.Created {
		t.Errorf("Created not merged in properly: dst.Created(%v) != src.Created(%v)", dst.Created, src.Created)
	}
}