@@ -5,11 +5,12 @@ import (
5
5
"errors"
6
6
"net/http"
7
7
"net/http/httptest"
8
+ "reflect"
8
9
"strings"
9
10
"testing"
10
11
)
11
12
12
- func mock_server (t * testing.T , expectedError error , hit * bool ) * httptest.Server {
13
+ func mock_server (t * testing.T , expectedError error , hit * bool , statsigOptions * map [ string ] interface {} ) * httptest.Server {
13
14
return httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
14
15
if strings .Contains (req .URL .Path , "/download_config_specs" ) {
15
16
res .WriteHeader (500 )
@@ -18,6 +19,9 @@ func mock_server(t *testing.T, expectedError error, hit *bool) *httptest.Server
18
19
if strings .Contains (req .URL .Path , "/sdk_exception" ) {
19
20
var body * logExceptionRequestBody
20
21
_ = json .NewDecoder (req .Body ).Decode (& body )
22
+ for key , value := range body .StatsigOptions {
23
+ (* statsigOptions )[key ] = value
24
+ }
21
25
if body .Exception != "" && (expectedError == nil || body .Exception == expectedError .Error ()) {
22
26
* hit = true
23
27
success := & logExceptionResponse {Success : true }
@@ -34,7 +38,8 @@ func mock_server(t *testing.T, expectedError error, hit *bool) *httptest.Server
34
38
func TestLogException (t * testing.T ) {
35
39
err := errors .New ("test error boundary log exception" )
36
40
hit := false
37
- testServer := mock_server (t , err , & hit )
41
+ statsigOption := make (map [string ]interface {})
42
+ testServer := mock_server (t , err , & hit , & statsigOption )
38
43
defer testServer .Close ()
39
44
opt := & Options {
40
45
API : testServer .URL ,
@@ -45,28 +50,44 @@ func TestLogException(t *testing.T) {
45
50
if ! hit {
46
51
t .Error ("Expected sdk_exception endpoint to be hit" )
47
52
}
53
+ if statsigOption ["API" ] != testServer .URL {
54
+ t .Error ("Expected statsigOptions to be set" )
55
+ }
48
56
}
49
57
50
58
func TestDCSError (t * testing.T ) {
51
59
hit := false
52
- testServer := mock_server (t , nil , & hit )
60
+ statsigOption := make (map [string ]interface {})
61
+ testServer := mock_server (t , nil , & hit , & statsigOption )
53
62
defer testServer .Close ()
63
+ dataadapter := dataAdapterExample {}
54
64
opt := & Options {
55
65
API : testServer .URL ,
56
66
OutputLoggerOptions : getOutputLoggerOptionsForTest (t ),
57
67
StatsigLoggerOptions : getStatsigLoggerOptionsForTest (t ),
68
+ DataAdapter : & dataadapter ,
58
69
}
59
70
InitializeWithOptions ("secret-key" , opt )
60
71
defer ShutdownAndDangerouslyClearInstance ()
61
72
if ! hit {
62
73
t .Error ("Expected sdk_exception endpoint to be hit" )
63
74
}
75
+ expectedStatsigLoggerOptions := map [string ]interface {}{
76
+ "DisableInitDiagnostics" : true ,
77
+ "DisableSyncDiagnostics" : true ,
78
+ "DisableApiDiagnostics" : true ,
79
+ "DisableAllLogging" : false ,
80
+ }
81
+ if ! reflect .DeepEqual (statsigOption ["StatsigLoggerOptions" ], expectedStatsigLoggerOptions ) {
82
+ t .Error ("Expected StatsigLoggerOptions in statsigOptions to be set" )
83
+ }
64
84
}
65
85
66
86
func TestRepeatedError (t * testing.T ) {
67
87
err := errors .New ("common error" )
68
88
hit := false
69
- testServer := mock_server (t , err , & hit )
89
+ statsigOption := make (map [string ]interface {})
90
+ testServer := mock_server (t , err , & hit , & statsigOption )
70
91
defer testServer .Close ()
71
92
opt := & Options {
72
93
API : testServer .URL ,
@@ -83,3 +104,39 @@ func TestRepeatedError(t *testing.T) {
83
104
t .Error ("Expected sdk_exception endpoint to NOT be hit" )
84
105
}
85
106
}
107
+
108
+ func TestStatsigOptions (t * testing.T ) {
109
+ hit := false
110
+ statsigOption := make (map [string ]interface {})
111
+ testServer := mock_server (t , nil , & hit , & statsigOption )
112
+ defer testServer .Close ()
113
+ opt := & Options {
114
+ API : testServer .URL ,
115
+ APIOverrides : APIOverrides {
116
+ DownloadConfigSpecs : testServer .URL ,
117
+ },
118
+ DataAdapter : & dataAdapterExample {},
119
+ IDListSyncInterval : 1 ,
120
+ IPCountryOptions : IPCountryOptions {
121
+ Disabled : true ,
122
+ LazyLoad : true ,
123
+ },
124
+ }
125
+ diagnostics := newDiagnostics (opt )
126
+ errorBoundary := newErrorBoundary ("client-key" , opt , diagnostics )
127
+ errorBoundary .logException (errors .New ("test error" ))
128
+ expectedOptions := map [string ]interface {}{
129
+ "API" : testServer .URL ,
130
+ "APIOverrides" : map [string ]interface {}{
131
+ "DownloadConfigSpecs" : testServer .URL ,
132
+ "GetIDLists" : "" ,
133
+ "LogEvent" : "" ,
134
+ },
135
+ "DataAdapter" : "set" ,
136
+ "IDListSyncInterval" : 1.0 ,
137
+ "IPCountryOptions" : "set" ,
138
+ }
139
+ if ! reflect .DeepEqual (statsigOption , expectedOptions ) {
140
+ t .Error ("Expected statsigOptions to be set" )
141
+ }
142
+ }
0 commit comments