Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge With Override And AppendSlice fails for map #94

Closed
prabhu43 opened this issue Jan 14, 2019 · 2 comments
Closed

Merge With Override And AppendSlice fails for map #94

prabhu43 opened this issue Jan 14, 2019 · 2 comments

Comments

@prabhu43
Copy link

Hi @imdario

We merged two maps with Override and also AppendSlice , which is taking Override as high precedence than AppendSlice for slices too.

Expected behaviour: We want Override for non-slice and AppendSlice for slice. The following Test should PASS, but it's failing currently

func TestMergeWithOverrideAndAppendSlice(t *testing.T) {
	aMap := map[string]interface{}{
		"key1": []int{3},
		"key2": "valueA2",
	}

	bMap := map[string]interface{}{
		"key1": []int{1, 2},
		"key2": "valueB2",
		"key3": "valueB3",
	}

	expectedMap := map[string]interface{}{
		"key1": []int{1, 2, 3},
		"key2": "valueB2",
		"key3": "valueB3",
	}
	err := Merge(&aMap, bMap, WithAppendSlice, WithOverride)

	if err != nil {
		t.Errorf("Test failed with error: %v", err)
	}

	if !reflect.DeepEqual(aMap, expectedMap) {
		t.Errorf("Actual: %#v did not match \nExpected: %#v", aMap, expectedMap)
	}
}

We went through the code and found it's because of this part of code

https://github.com/imdario/mergo/blob/master/merge.go#L139

Could you explain the meaning for this code?

@darccio
Copy link
Owner

darccio commented Jan 23, 2019

Sorry for not answering before. Please test this against the last release (v0.3.7) as it fixes some bugs related to Override.

@prabhu43
Copy link
Author

@imdario It's working as expected in the new version. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants