@@ -4,7 +4,10 @@ package event
44// scenarios. These tests will not log anything.
55
66import (
7+ "reflect"
78 "testing"
9+
10+ "github.com/posthog/posthog-go"
811)
912
1013func TestError(t *testing.T) {
@@ -59,6 +62,33 @@ func TestError(t *testing.T) {
5962 })
6063}
6164
65+func TestPairsToProps(t *testing.T) {
66+ t.Run("sets valid key value pairs", func(t *testing.T) {
67+ got := pairsToProps("foo", "bar", "count", 3)
68+ want := posthog.NewProperties().
69+ Set("foo", "bar").
70+ Set("count", 3)
71+ if !reflect.DeepEqual(got, want) {
72+ t.Fatalf("pairsToProps() = %#v, want %#v", got, want)
73+ }
74+ })
75+
76+ t.Run("returns empty properties for odd pairs", func(t *testing.T) {
77+ got := pairsToProps("foo", "bar", "count")
78+ if len(got) != 0 {
79+ t.Fatalf("pairsToProps() should return empty properties, got %#v", got)
80+ }
81+ })
82+
83+ t.Run("ignores non-string key and continues", func(t *testing.T) {
84+ got := pairsToProps(123, "bad", "ok", true)
85+ want := posthog.NewProperties().Set("ok", true)
86+ if !reflect.DeepEqual(got, want) {
87+ t.Fatalf("pairsToProps() = %#v, want %#v", got, want)
88+ }
89+ })
90+}
91+
6292// newDefaultTestError creates a test error that mimics runtime panic
6393// errors. This helps us testing that the Error function can handle various
6494// error types, including those that might be passed from a panic recovery