forked from statsig-io/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_override_test.go
129 lines (118 loc) · 3.25 KB
/
api_override_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package statsig
import (
"net/http/httptest"
"testing"
)
type counters struct {
dcs int
getIDLists int
logEvent int
}
func setupTestServer(counts *counters) *httptest.Server {
return getTestServer(testServerOptions{
dcsOnline: true,
onLogEvent: func(events []map[string]interface{}) {
counts.logEvent += 1
},
onDCS: func() {
counts.dcs += 1
},
onGetIDLists: func() {
counts.getIDLists += 1
},
})
}
func TestAPIOverride(t *testing.T) {
counts := &counters{dcs: 0, getIDLists: 0, logEvent: 0}
testServer := setupTestServer(counts)
opts := &Options{
API: testServer.URL,
OutputLoggerOptions: getOutputLoggerOptionsForTest(t),
StatsigLoggerOptions: getStatsigLoggerOptionsForTest(t),
}
InitializeWithOptions("secret-key", opts)
user := User{UserID: "some_user_id"}
CheckGate(user, "test_gate")
ShutdownAndDangerouslyClearInstance()
if counts.dcs < 1 {
t.Error("Expected call to download_config_specs")
}
if counts.getIDLists < 1 {
t.Error("Expected call to get_id_lists")
}
if counts.logEvent < 1 {
t.Error("Expected call to log_event")
}
}
func TestAPIOverrideDCS(t *testing.T) {
counts := &counters{dcs: 0, getIDLists: 0, logEvent: 0}
testServer := setupTestServer(counts)
opts := &Options{
APIOverrides: APIOverrides{
DownloadConfigSpecs: testServer.URL,
},
OutputLoggerOptions: getOutputLoggerOptionsForTest(t),
StatsigLoggerOptions: getStatsigLoggerOptionsForTest(t),
}
InitializeWithOptions("secret-key", opts)
user := User{UserID: "some_user_id"}
CheckGate(user, "test_gate")
ShutdownAndDangerouslyClearInstance()
if counts.dcs < 1 {
t.Error("Expected call to download_config_specs")
}
if counts.getIDLists != 0 {
t.Error("Expected zero calls to get_id_lists")
}
if counts.logEvent != 0 {
t.Error("Expected zero calls to log_event")
}
}
func TestAPIOverrideGetIDLists(t *testing.T) {
counts := &counters{dcs: 0, getIDLists: 0, logEvent: 0}
testServer := setupTestServer(counts)
opts := &Options{
APIOverrides: APIOverrides{
GetIDLists: testServer.URL,
},
OutputLoggerOptions: getOutputLoggerOptionsForTest(t),
StatsigLoggerOptions: getStatsigLoggerOptionsForTest(t),
}
InitializeWithOptions("secret-key", opts)
user := User{UserID: "some_user_id"}
CheckGate(user, "test_gate")
ShutdownAndDangerouslyClearInstance()
if counts.dcs != 0 {
t.Error("Expected zero calls to download_config_specs")
}
if counts.getIDLists < 1 {
t.Error("Expected call to get_id_lists")
}
if counts.logEvent != 0 {
t.Error("Expected zero calls to log_event")
}
}
func TestAPIOverrideLogEvent(t *testing.T) {
counts := &counters{dcs: 0, getIDLists: 0, logEvent: 0}
testServer := setupTestServer(counts)
opts := &Options{
APIOverrides: APIOverrides{
LogEvent: testServer.URL,
},
OutputLoggerOptions: getOutputLoggerOptionsForTest(t),
StatsigLoggerOptions: getStatsigLoggerOptionsForTest(t),
}
InitializeWithOptions("secret-key", opts)
user := User{UserID: "some_user_id"}
CheckGate(user, "test_gate")
ShutdownAndDangerouslyClearInstance()
if counts.dcs != 0 {
t.Error("Expected zero calls to download_config_specs")
}
if counts.getIDLists != 0 {
t.Error("Expected zero call to get_id_lists")
}
if counts.logEvent < 1 {
t.Error("Expected call to log_event")
}
}