forked from growthbook/growthbook-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditions_test.go
37 lines (32 loc) · 1.07 KB
/
conditions_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
package growthbook
import "testing"
func TestConditionValueNullOrNotPresent(t *testing.T) {
condition := ParseCondition([]byte(`{"userId": null}`))
result := condition.Eval(Attributes{"userId": nil})
if result != true {
t.Error("1: expected condition evaluation to be true")
}
condition = ParseCondition([]byte(`{}`))
result = condition.Eval(Attributes{"userId": nil})
if result != true {
t.Error("2: expected condition evaluation to be true")
}
}
func TestConditionValueIsPresent(t *testing.T) {
condition := ParseCondition([]byte(`{"userId": null}`))
result := condition.Eval(Attributes{"userId": "123"})
if result != false {
t.Error("1: expected condition evaluation to be false")
}
}
func TestConditionValueIsPresentButFalsy(t *testing.T) {
condition := ParseCondition([]byte(`{"userId": null}`))
result := condition.Eval(Attributes{"userId": 0})
if result != false {
t.Error("1: expected condition evaluation to be false")
}
result = condition.Eval(Attributes{"userId": ""})
if result != false {
t.Error("2: expected condition evaluation to be false")
}
}