forked from statsig-io/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overrides_test.go
77 lines (63 loc) · 2.14 KB
/
overrides_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package statsig
import (
"reflect"
"testing"
)
func TestOverrides(t *testing.T) {
InitializeGlobalOutputLogger(getOutputLoggerOptionsForTest(t))
c := NewClientWithOptions(secret, &Options{
LocalMode: true,
})
user := User{
UserID: "123",
Email: "[email protected]",
}
gateDefault := c.CheckGate(user, "any_gate")
if gateDefault != false {
t.Errorf("Failed to get default value for a gate when in LocalMode")
}
c.OverrideGate("any_gate", true)
gateOverride := c.CheckGate(user, "any_gate")
if gateOverride != true {
t.Errorf("Failed to get override value for a gate when in LocalMode")
}
c.OverrideGate("any_gate", false)
newGateOverride := c.CheckGate(user, "any_gate")
if newGateOverride != false {
t.Errorf("Failed to get override value for a gate when in LocalMode")
}
configDefault := c.GetConfig(user, "any_config")
if len(configDefault.Value) != 0 {
t.Errorf("Failed to get default value for a config when in LocalMode")
}
config := make(map[string]interface{})
config["test"] = 123
c.OverrideConfig("any_config", config)
configOverride := c.GetConfig(user, "any_config")
if !reflect.DeepEqual(configOverride.Value, config) {
t.Errorf("Failed to get override value for a config when in LocalMode")
}
newConfig := make(map[string]interface{})
newConfig["test"] = 456
newConfig["test2"] = "hello"
c.OverrideConfig("any_config", newConfig)
newConfigOverride := c.GetConfig(user, "any_config")
if !reflect.DeepEqual(newConfigOverride.Value, newConfig) {
t.Errorf("Failed to get override value for a config when in LocalMode")
}
layer := make(map[string]interface{})
layer["test"] = 123
c.OverrideLayer("any_layer", layer)
layerOverride := c.GetLayer(user, "any_layer")
if !reflect.DeepEqual(layerOverride.Value, layer) {
t.Errorf("Failed to get override value for a layer when in LocalMode")
}
newLayer := make(map[string]interface{})
newLayer["test"] = 456
newLayer["test2"] = "hello"
c.OverrideLayer("any_layer", newLayer)
newLayerOverride := c.GetLayer(user, "any_layer")
if !reflect.DeepEqual(newLayerOverride.Value, newLayer) {
t.Errorf("Failed to get override value for a layer when in LocalMode")
}
}