...

Source file src/dario.cat/mergo/issue90_test.go

Documentation: dario.cat/mergo

     1  package mergo_test
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"dario.cat/mergo"
     8  )
     9  
    10  type structWithStringMap struct {
    11  	Data map[string]string
    12  }
    13  
    14  func TestIssue90(t *testing.T) {
    15  	dst := map[string]structWithStringMap{
    16  		"struct": {
    17  			Data: nil,
    18  		},
    19  	}
    20  	src := map[string]structWithStringMap{
    21  		"struct": {
    22  			Data: map[string]string{
    23  				"foo": "bar",
    24  			},
    25  		},
    26  	}
    27  	expected := map[string]structWithStringMap{
    28  		"struct": {
    29  			Data: map[string]string{
    30  				"foo": "bar",
    31  			},
    32  		},
    33  	}
    34  
    35  	err := mergo.Merge(&dst, src, mergo.WithOverride)
    36  	if err != nil {
    37  		t.Errorf("unexpected error %v", err)
    38  	}
    39  
    40  	if !reflect.DeepEqual(dst, expected) {
    41  		t.Errorf("expected: %#v\ngot: %#v", expected, dst)
    42  	}
    43  }
    44  

View as plain text