Skip to content

Commit c5dea82

Browse files
author
evgeny.iva
committed
Merge remote-tracking branch 'origin/master'
2 parents 101b879 + 1de931c commit c5dea82

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.2.18
2+
3+
* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.17...v1.2.18)
4+
5+
## 1.2.17
6+
7+
* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.16...v1.2.17)
8+
19
## 1.2.16
210

311
* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.15...v1.2.16)

posthog.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ func (c *client) Enqueue(msg Message) (err error) {
230230
}
231231
m.Properties["$active_feature_flags"] = featureKeys
232232
}
233+
if m.Properties == nil {
234+
m.Properties = NewProperties()
235+
}
233236
m.Properties.Merge(c.DefaultEventProperties)
234237
c.setLastCapturedEvent(m)
235238
msg = m

posthog_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,33 @@ func ExampleCapture() {
229229
// }
230230
// ]
231231
// }
232+
}
233+
234+
func TestCaptureNoProperties(t *testing.T) {
235+
defer func() {
236+
// Ensure that the test doesn't panic.
237+
if recover() != nil {
238+
t.Error("shouldnt have panicked when merging properties into nil properties")
239+
}
240+
}()
241+
242+
_, server := mockServer()
243+
defer server.Close()
232244

245+
client, _ := NewWithConfig("Csyjlnlun3OzyNJAafdlv", Config{
246+
Endpoint: server.URL,
247+
BatchSize: 1,
248+
now: mockTime,
249+
uid: mockId,
250+
DefaultEventProperties: NewProperties().Set("service", "api"),
251+
})
252+
defer client.Close()
253+
254+
client.Enqueue(Capture{
255+
Event: "Download",
256+
DistinctId: "123456",
257+
SendFeatureFlags: false,
258+
})
233259
}
234260

235261
func TestEnqueue(t *testing.T) {

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
}

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package posthog
33
import "flag"
44

55
// Version of the client.
6-
const Version = "1.2.16"
6+
const Version = "1.2.18"
77

88
// make tests easier by using a constant version
99
func getVersion() string {

0 commit comments

Comments
 (0)