@@ -148,6 +148,116 @@ func TestClientInitializeResponseOptions(t *testing.T) {
148
148
}
149
149
}
150
150
151
+ func TestClientInitializeResponseFilterOptions (t * testing.T ) {
152
+ user := User {
153
+ UserID : "123" ,
154
+
155
+ Country : "US" ,
156
+ Custom : map [string ]interface {}{"test" : "123" },
157
+ CustomIDs : map [string ]string {"stableID" : "12345" },
158
+ }
159
+
160
+ InitializeWithOptions (secret , & Options {
161
+ OutputLoggerOptions : getOutputLoggerOptionsForTest (t ),
162
+ StatsigLoggerOptions : getStatsigLoggerOptionsForTest (t ),
163
+ })
164
+ defer ShutdownAndDangerouslyClearInstance ()
165
+
166
+ tests := []struct {
167
+ name string
168
+ filter * GCIROptions
169
+ expectGate bool
170
+ expectDC bool
171
+ expectExp bool
172
+ expectAT bool
173
+ expectLayer bool
174
+ }{
175
+ {
176
+ name : "Include all entities" ,
177
+ filter : & GCIROptions {HashAlgorithm : "none" },
178
+ expectGate : true , expectDC : true , expectExp : true , expectAT : true , expectLayer : true ,
179
+ },
180
+ {
181
+ name : "Only feature gates" ,
182
+ filter : & GCIROptions {HashAlgorithm : "none" , ConfigTypesToInclude : []ConfigType {FeatureGateType }},
183
+ expectGate : true , expectDC : false , expectExp : false , expectAT : false , expectLayer : false ,
184
+ },
185
+ {
186
+ name : "Only dynamic configs" ,
187
+ filter : & GCIROptions {HashAlgorithm : "none" , ConfigTypesToInclude : []ConfigType {DynamicConfigType }},
188
+ expectGate : false , expectDC : true , expectExp : false , expectAT : false , expectLayer : false ,
189
+ },
190
+ {
191
+ name : "Only experiments" ,
192
+ filter : & GCIROptions {HashAlgorithm : "none" , ConfigTypesToInclude : []ConfigType {ExperimentType }},
193
+ expectGate : false , expectDC : false , expectExp : true , expectAT : false , expectLayer : false ,
194
+ },
195
+ {
196
+ name : "Only autotune configs" ,
197
+ filter : & GCIROptions {HashAlgorithm : "none" , ConfigTypesToInclude : []ConfigType {AutotuneType }},
198
+ expectGate : false , expectDC : false , expectExp : false , expectAT : true , expectLayer : false ,
199
+ },
200
+ {
201
+ name : "Only layers" ,
202
+ filter : & GCIROptions {HashAlgorithm : "none" , ConfigTypesToInclude : []ConfigType {LayerType }},
203
+ expectGate : false , expectDC : false , expectExp : false , expectAT : false , expectLayer : true ,
204
+ },
205
+ {
206
+ name : "Include multiple entities (feature gates and experiments)" ,
207
+ filter : & GCIROptions {HashAlgorithm : "none" , ConfigTypesToInclude : []ConfigType {FeatureGateType , ExperimentType }},
208
+ expectGate : true , expectDC : false , expectExp : true , expectAT : false , expectLayer : false ,
209
+ },
210
+ }
211
+
212
+ for _ , tt := range tests {
213
+ t .Run (tt .name , func (t * testing.T ) {
214
+ response := GetClientInitializeResponseWithOptions (user , tt .filter )
215
+
216
+ var featureGate GateInitializeResponse
217
+ var dynamicConfig ConfigInitializeResponse
218
+ var experiment ConfigInitializeResponse
219
+ var autotune ConfigInitializeResponse
220
+ var layer LayerInitializeResponse
221
+
222
+ for _ , g := range response .FeatureGates {
223
+ if g .Name == "test_public" {
224
+ featureGate = g
225
+ }
226
+ }
227
+ for _ , c := range response .DynamicConfigs {
228
+ if c .Name == "test_custom_config" {
229
+ dynamicConfig = c
230
+ } else if c .Name == "test_experiment_with_targeting" {
231
+ experiment = c
232
+ } else if c .Name == "test_autotune" {
233
+ autotune = c
234
+ }
235
+ }
236
+ for _ , l := range response .LayerConfigs {
237
+ if l .Name == "Basic_test_layer" {
238
+ layer = l
239
+ }
240
+ }
241
+
242
+ if (featureGate .Name != "" ) != tt .expectGate {
243
+ t .Errorf ("Feature gate presence mismatch: got %v, want %v" , featureGate .Name != "" , tt .expectGate )
244
+ }
245
+ if (dynamicConfig .Name != "" ) != tt .expectDC {
246
+ t .Errorf ("Dynamic config presence mismatch: got %v, want %v" , dynamicConfig .Name != "" , tt .expectDC )
247
+ }
248
+ if (experiment .Name != "" ) != tt .expectExp {
249
+ t .Errorf ("Experiment presence mismatch: got %v, want %v" , experiment .Name != "" , tt .expectExp )
250
+ }
251
+ if (autotune .Name != "" ) != tt .expectAT {
252
+ t .Errorf ("Autotune config presence mismatch: got %v, want %v" , autotune .Name != "" , tt .expectAT )
253
+ }
254
+ if (layer .Name != "" ) != tt .expectLayer {
255
+ t .Errorf ("Layer presence mismatch: got %v, want %v" , layer .Name != "" , tt .expectLayer )
256
+ }
257
+ })
258
+ }
259
+ }
260
+
151
261
func filterHttpResponseAndReadBody (httpResponse * http.Response ) ([]byte , error ) {
152
262
var interfaceBody ClientInitializeResponse
153
263
// Initialize nullable fields so that JSON Unmarshal doesn't convert to null
0 commit comments