forked from statsig-io/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statsig_metadata_test.go
53 lines (50 loc) · 1.52 KB
/
statsig_metadata_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
package statsig
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func makeTestServer(reqCallback func(req *http.Request)) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
reqCallback(req)
}))
}
func TestStatsigMetadata(t *testing.T) {
sessionID := ""
InitializeWithOptions("secret-key", &Options{
API: makeTestServer(func(req *http.Request) {
reqSessionID := req.Header.Get("STATSIG-SERVER-SESSION-ID")
if strings.Contains(req.URL.Path, "download_config_specs") {
sessionID = reqSessionID
}
if strings.Contains(req.URL.Path, "log_event") {
if reqSessionID != sessionID {
t.Error("Inconsistent SessionID")
}
}
}).URL,
OutputLoggerOptions: getOutputLoggerOptionsForTest(t),
StatsigLoggerOptions: getStatsigLoggerOptionsForTest(t),
LoggingMaxBufferSize: 1,
})
if sessionID == "" {
t.Error("Missing SessionID in statsig metadata")
}
CheckGate(User{UserID: "first"}, "non-existent")
Shutdown()
InitializeWithOptions("secret-key", &Options{
API: makeTestServer(func(req *http.Request) {
reqSessionID := req.Header.Get("STATSIG-SERVER-SESSION-ID")
if strings.Contains(req.URL.Path, "download_config_specs") {
if reqSessionID == sessionID {
t.Error("SessionID not reset on Initialize")
}
}
}).URL,
OutputLoggerOptions: getOutputLoggerOptionsForTest(t),
StatsigLoggerOptions: getStatsigLoggerOptionsForTest(t),
})
ShutdownAndDangerouslyClearInstance()
}