...

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

Documentation: dario.cat/mergo

     1  package mergo_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"dario.cat/mergo"
     7  )
     8  
     9  func TestMapInterfaceWithMultipleLayer(t *testing.T) {
    10  	m1 := map[string]interface{}{
    11  		"k1": map[string]interface{}{
    12  			"k1.1": "v1",
    13  		},
    14  	}
    15  
    16  	m2 := map[string]interface{}{
    17  		"k1": map[string]interface{}{
    18  			"k1.1": "v2",
    19  			"k1.2": "v3",
    20  		},
    21  	}
    22  
    23  	if err := mergo.Map(&m1, m2, mergo.WithOverride); err != nil {
    24  		t.Errorf("Error merging: %v", err)
    25  	}
    26  
    27  	// Check overwrite of sub map works
    28  	expected := "v2"
    29  	actual := m1["k1"].(map[string]interface{})["k1.1"].(string)
    30  	if actual != expected {
    31  		t.Errorf("Expected %v but got %v",
    32  			expected,
    33  			actual)
    34  	}
    35  
    36  	// Check new key is merged
    37  	expected = "v3"
    38  	actual = m1["k1"].(map[string]interface{})["k1.2"].(string)
    39  	if actual != expected {
    40  		t.Errorf("Expected %v but got %v",
    41  			expected,
    42  			actual)
    43  	}
    44  }
    45  

View as plain text