-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from ndeloof/master
use src map if dst is nil and can't be set
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mergo_test | ||
|
||
import ( | ||
"github.com/imdario/mergo" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
type structWithStringMap struct { | ||
Data map[string]string | ||
} | ||
|
||
|
||
func TestIssue90(t *testing.T) { | ||
dst := map[string]structWithStringMap{ | ||
"struct": { | ||
Data: nil, | ||
}, | ||
} | ||
src := map[string]structWithStringMap{ | ||
"struct": { | ||
Data: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
} | ||
expected := map[string]structWithStringMap{ | ||
"struct": { | ||
Data: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
}, | ||
} | ||
|
||
err := mergo.Merge(&dst, src, mergo.WithOverride) | ||
if err != nil { | ||
t.Errorf("unexpected error %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(dst, expected) { | ||
t.Errorf("expected: %#v\ngot: %#v", expected, dst) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters