...

Source file src/github.com/imdario/mergo/issue89_test.go

Documentation: github.com/imdario/mergo

     1  package mergo_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/imdario/mergo"
     7  )
     8  
     9  func TestIssue89Boolean(t *testing.T) {
    10  	type Foo struct {
    11  		Bar bool `json:"bar"`
    12  	}
    13  
    14  	src := Foo{Bar: true}
    15  	dst := Foo{Bar: false}
    16  
    17  	if err := mergo.Merge(&dst, src); err != nil {
    18  		t.Error(err)
    19  	}
    20  	if dst.Bar == false {
    21  		t.Errorf("expected true, got false")
    22  	}
    23  }
    24  
    25  func TestIssue89MergeWithEmptyValue(t *testing.T) {
    26  	p1 := map[string]interface{}{
    27  		"A": 3, "B": "note", "C": true,
    28  	}
    29  	p2 := map[string]interface{}{
    30  		"B": "", "C": false,
    31  	}
    32  	if err := mergo.Merge(&p1, p2, mergo.WithOverwriteWithEmptyValue); err != nil {
    33  		t.Error(err)
    34  	}
    35  	testCases := []struct {
    36  		expected interface{}
    37  		key      string
    38  	}{
    39  		{
    40  			"",
    41  			"B",
    42  		},
    43  		{
    44  			false,
    45  			"C",
    46  		},
    47  	}
    48  	for _, tC := range testCases {
    49  		if p1[tC.key] != tC.expected {
    50  			t.Errorf("expected %v in p1[%q], got %v", tC.expected, tC.key, p1[tC.key])
    51  		}
    52  	}
    53  }
    54  

View as plain text