...

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

Documentation: dario.cat/mergo

     1  package mergo_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"dario.cat/mergo"
     8  )
     9  
    10  func TestIssue143(t *testing.T) {
    11  	testCases := []struct {
    12  		expected func(map[string]interface{}) error
    13  		options  []func(*mergo.Config)
    14  	}{
    15  		{
    16  			options: []func(*mergo.Config){mergo.WithOverride},
    17  			expected: func(m map[string]interface{}) error {
    18  				properties := m["properties"].(map[string]interface{})
    19  				if properties["field1"] != "wrong" {
    20  					return fmt.Errorf("expected %q, got %v", "wrong", properties["field1"])
    21  				}
    22  				return nil
    23  			},
    24  		},
    25  		{
    26  			options: []func(*mergo.Config){},
    27  			expected: func(m map[string]interface{}) error {
    28  				properties := m["properties"].(map[string]interface{})
    29  				if properties["field1"] == "wrong" {
    30  					return fmt.Errorf("expected a map, got %v", "wrong")
    31  				}
    32  				return nil
    33  			},
    34  		},
    35  	}
    36  	for _, tC := range testCases {
    37  		base := map[string]interface{}{
    38  			"properties": map[string]interface{}{
    39  				"field1": map[string]interface{}{
    40  					"type": "text",
    41  				},
    42  			},
    43  		}
    44  
    45  		err := mergo.Map(
    46  			&base,
    47  			map[string]interface{}{
    48  				"properties": map[string]interface{}{
    49  					"field1": "wrong",
    50  				},
    51  			},
    52  			tC.options...,
    53  		)
    54  		if err != nil {
    55  			t.Error(err)
    56  		}
    57  		if err := tC.expected(base); err != nil {
    58  			t.Error(err)
    59  		}
    60  	}
    61  }
    62  

View as plain text