-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstance_individually_named_segments_test.go
More file actions
85 lines (75 loc) · 2.33 KB
/
instance_individually_named_segments_test.go
File metadata and controls
85 lines (75 loc) · 2.33 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package featurevisor
import (
"testing"
)
func TestIndividuallyNamedSegments(t *testing.T) {
jsonDatafile := `{
"schemaVersion": "2",
"revision": "1.0",
"features": {
"test": {
"key": "test",
"bucketBy": "userId",
"traffic": [
{
"key": "1",
"segments": "netherlands",
"percentage": 100000,
"allocation": []
},
{
"key": "2",
"segments": "[\"iphone\",\"unitedStates\"]",
"percentage": 100000,
"allocation": []
}
]
}
},
"segments": {
"netherlands": {
"key": "netherlands",
"conditions": "[{\"attribute\":\"country\",\"operator\":\"equals\",\"value\":\"nl\"}]"
},
"iphone": {
"key": "iphone",
"conditions": "[{\"attribute\":\"device\",\"operator\":\"equals\",\"value\":\"iphone\"}]"
},
"unitedStates": {
"key": "unitedStates",
"conditions": "[{\"attribute\":\"country\",\"operator\":\"equals\",\"value\":\"us\"}]"
}
}
}`
var datafile DatafileContent
if err := datafile.FromJSON(jsonDatafile); err != nil {
t.Fatalf("Failed to parse datafile JSON: %v", err)
}
sdk := CreateInstance(Options{
Datafile: datafile,
})
// Should be disabled for no context
if sdk.IsEnabled("test", Context{}, OverrideOptions{}) {
t.Error("Expected feature to be disabled for no context")
}
// Should be disabled for users without matching segments
if sdk.IsEnabled("test", Context{"userId": "123"}, OverrideOptions{}) {
t.Error("Expected feature to be disabled for users without matching segments")
}
// Should be disabled for German users
if sdk.IsEnabled("test", Context{"userId": "123", "country": "de"}, OverrideOptions{}) {
t.Error("Expected feature to be disabled for German users")
}
// Should be disabled for US users without iPhone
if sdk.IsEnabled("test", Context{"userId": "123", "country": "us"}, OverrideOptions{}) {
t.Error("Expected feature to be disabled for US users without iPhone")
}
// Should be enabled for Dutch users
if !sdk.IsEnabled("test", Context{"userId": "123", "country": "nl"}, OverrideOptions{}) {
t.Error("Expected feature to be enabled for Dutch users")
}
// Should be enabled for US users with iPhone
if !sdk.IsEnabled("test", Context{"userId": "123", "country": "us", "device": "iphone"}, OverrideOptions{}) {
t.Error("Expected feature to be enabled for US users with iPhone")
}
}