Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny.iva committed Aug 19, 2024
2 parents 101b879 + 1de931c commit c5dea82
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.2.18

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.17...v1.2.18)

## 1.2.17

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

## 1.2.16

* [Full Changelog](https://github.com/PostHog/posthog-go/compare/v1.2.15...v1.2.16)
Expand Down
3 changes: 3 additions & 0 deletions posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ func (c *client) Enqueue(msg Message) (err error) {
}
m.Properties["$active_feature_flags"] = featureKeys
}
if m.Properties == nil {
m.Properties = NewProperties()
}
m.Properties.Merge(c.DefaultEventProperties)
c.setLastCapturedEvent(m)
msg = m
Expand Down
26 changes: 26 additions & 0 deletions posthog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,33 @@ func ExampleCapture() {
// }
// ]
// }
}

func TestCaptureNoProperties(t *testing.T) {
defer func() {
// Ensure that the test doesn't panic.
if recover() != nil {
t.Error("shouldnt have panicked when merging properties into nil properties")
}
}()

_, server := mockServer()
defer server.Close()

client, _ := NewWithConfig("Csyjlnlun3OzyNJAafdlv", Config{
Endpoint: server.URL,
BatchSize: 1,
now: mockTime,
uid: mockId,
DefaultEventProperties: NewProperties().Set("service", "api"),
})
defer client.Close()

client.Enqueue(Capture{
Event: "Download",
DistinctId: "123456",
SendFeatureFlags: false,
})
}

func TestEnqueue(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (p Properties) Set(name string, value interface{}) Properties {
// Merge adds the properties from the provided `props` into the receiver `p`.
// If a property in `props` already exists in `p`, its value will be overwritten.
func (p Properties) Merge(props Properties) Properties {
if props == nil {
return p
}

for k, v := range props {
p[k] = v
}
Expand Down
13 changes: 12 additions & 1 deletion properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ func TestPropertiesMerge(t *testing.T) {

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

if !reflect.DeepEqual(props, Properties{"title": "A", "value": 0.5, "currency": "USD", "service": "api"}) {
if !reflect.DeepEqual(props, expected) {
t.Errorf("invalid properties produced by merge:\n- expected %#v\n- found: %#v", expected, props)
}
}

func TestPropertiesMergeNil(t *testing.T) {
props := NewProperties().Set("title", "A")
props.Merge(nil)

expected := Properties{"title": "A"}

if !reflect.DeepEqual(props, expected) {
t.Errorf("invalid properties produced by merge:\n- expected %#v\n- found: %#v", expected, props)
}
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package posthog
import "flag"

// Version of the client.
const Version = "1.2.16"
const Version = "1.2.18"

// make tests easier by using a constant version
func getVersion() string {
Expand Down

0 comments on commit c5dea82

Please sign in to comment.