Skip to content

Commit 7a9f2bd

Browse files
committed
Properties.Merge: check for nil
1 parent 3941ef1 commit 7a9f2bd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

properties.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func (p Properties) Set(name string, value interface{}) Properties {
2626
// Merge adds the properties from the provided `props` into the receiver `p`.
2727
// If a property in `props` already exists in `p`, its value will be overwritten.
2828
func (p Properties) Merge(props Properties) Properties {
29+
if props == nil {
30+
return p
31+
}
32+
2933
for k, v := range props {
3034
p[k] = v
3135
}

properties_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ func TestPropertiesMerge(t *testing.T) {
4444

4545
expected := Properties{"title": "A", "value": 0.5, "currency": "USD", "service": "api"}
4646

47-
if !reflect.DeepEqual(props, Properties{"title": "A", "value": 0.5, "currency": "USD", "service": "api"}) {
47+
if !reflect.DeepEqual(props, expected) {
48+
t.Errorf("invalid properties produced by merge:\n- expected %#v\n- found: %#v", expected, props)
49+
}
50+
}
51+
52+
func TestPropertiesMergeNil(t *testing.T) {
53+
props := NewProperties().Set("title", "A")
54+
props.Merge(nil)
55+
56+
expected := Properties{"title": "A"}
57+
58+
if !reflect.DeepEqual(props, expected) {
4859
t.Errorf("invalid properties produced by merge:\n- expected %#v\n- found: %#v", expected, props)
4960
}
5061
}

0 commit comments

Comments
 (0)