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

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

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

6e78443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2128e0d
6e78443
 
 
2128e0d
6e78443
 
 
2128e0d
6e78443
 
 
2128e0d
6e78443
 
 
 
 
 
 
 
package mergo_test

import (
	"testing"

	"github.com/imdario/mergo"
)

func TestIssue123(t *testing.T) {
	src := map[string]interface{}{
		"col1": nil,
		"col2": 4,
		"col3": nil,
	}
	dst := map[string]interface{}{
		"col1": 2,
		"col2": 3,
		"col3": 3,
	}

	// Expected behavior
	if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
		t.Fatal(err)
	}
	testCases := []struct {
		expected interface{}
		key      string
	}{
		{
			nil,
			"col1",
		},
		{
			4,
			"col2",
		},
		{
			nil,
			"col3",
		},
	}
	for _, tC := range testCases {
		if dst[tC.key] != tC.expected {
			t.Fatalf("expected %v in dst[%q], got %v", tC.expected, tC.key, dst[tC.key])
		}
	}
}