-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstance_variables_no_variations_test.go
More file actions
71 lines (64 loc) · 1.5 KB
/
instance_variables_no_variations_test.go
File metadata and controls
71 lines (64 loc) · 1.5 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
package featurevisor
import (
"testing"
)
func TestVariablesWithoutVariations(t *testing.T) {
jsonDatafile := `{
"schemaVersion": "2",
"revision": "1.0",
"segments": {
"netherlands": {
"key": "netherlands",
"conditions": "[{\"attribute\":\"country\",\"operator\":\"equals\",\"value\":\"nl\"}]"
}
},
"features": {
"test": {
"key": "test",
"bucketBy": "userId",
"variablesSchema": {
"color": {
"key": "color",
"type": "string",
"defaultValue": "red"
}
},
"traffic": [
{
"key": "1",
"segments": "netherlands",
"percentage": 100000,
"variables": {
"color": "orange"
},
"allocation": []
},
{
"key": "2",
"segments": "*",
"percentage": 100000,
"allocation": []
}
]
}
}
}`
var datafile DatafileContent
if err := datafile.FromJSON(jsonDatafile); err != nil {
t.Fatalf("Failed to parse datafile JSON: %v", err)
}
sdk := CreateInstance(Options{
Datafile: datafile,
})
defaultContext := Context{"userId": "123"}
// Test default value
color := sdk.GetVariable("test", "color", defaultContext, OverrideOptions{})
if color != "red" {
t.Errorf("Expected color to be 'red' for default context, got '%v'", color)
}
// Test override for Dutch users
color = sdk.GetVariable("test", "color", Context{"userId": "123", "country": "nl"}, OverrideOptions{})
if color != "orange" {
t.Errorf("Expected color to be 'orange' for Dutch users, got '%v'", color)
}
}