forked from PostHog/posthog-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
properties_test.go
61 lines (47 loc) · 1.58 KB
/
properties_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package posthog
import (
"reflect"
"testing"
)
func TestPropertiesSimple(t *testing.T) {
text := "ABC"
number := 0.5
tests := map[string]struct {
ref Properties
run func(Properties)
}{
"revenue": {Properties{"revenue": number}, func(p Properties) { p.Set("revenue", number) }},
"currency": {Properties{"currency": text}, func(p Properties) { p.Set("currency", text) }},
}
for name, test := range tests {
prop := NewProperties()
test.run(prop)
if !reflect.DeepEqual(prop, test.ref) {
t.Errorf("%s: invalid properties produced: %#v\n", name, prop)
}
}
}
func TestPropertiesMulti(t *testing.T) {
p0 := Properties{"title": "A", "value": 0.5}
p1 := NewProperties().Set("title", "A").Set("value", 0.5)
if !reflect.DeepEqual(p0, p1) {
t.Errorf("invalid properties produced by chained setters:\n- expected %#v\n- found: %#v", p0, p1)
}
}
func TestPropertiesMerge(t *testing.T) {
defaultProps := Properties{"currency": "USD", "service": "api"}
props := NewProperties().Set("title", "A").Set("value", 0.5).Set("currency", "BRL")
props.Merge(defaultProps)
expected := 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)
}
}