@@ -15,11 +15,12 @@ func TestFractionalEvaluation(t *testing.T) {
15
15
var sources = []string {source }
16
16
ctx := context .Background ()
17
17
18
- commonFlags := map [string ]model.Flag {
19
- "headerColor" : {
18
+ commonFlags := []model.Flag {
19
+ {
20
+ Key : "headerColor" ,
20
21
State : "ENABLED" ,
21
22
DefaultVariant : "red" ,
22
- Variants : colorVariants ,
23
+ Variants : colorVariants ,
23
24
Targeting : []byte (`{
24
25
"if": [
25
26
{
@@ -51,10 +52,11 @@ func TestFractionalEvaluation(t *testing.T) {
51
52
]
52
53
}` ),
53
54
},
54
- "customSeededHeaderColor" : {
55
+ {
56
+ Key : "customSeededHeaderColor" ,
55
57
State : "ENABLED" ,
56
58
DefaultVariant : "red" ,
57
- Variants : colorVariants ,
59
+ Variants : colorVariants ,
58
60
Targeting : []byte (`{
59
61
"if": [
60
62
{
@@ -77,7 +79,7 @@ func TestFractionalEvaluation(t *testing.T) {
77
79
}
78
80
79
81
tests := map [string ]struct {
80
- flags map [ string ]model.Flag
82
+ flags [ ]model.Flag
81
83
flagKey string
82
84
context map [string ]any
83
85
expectedValue string
@@ -166,12 +168,12 @@ func TestFractionalEvaluation(t *testing.T) {
166
168
expectedReason : model .TargetingMatchReason ,
167
169
},
168
170
"[email protected] with different flag key" : {
169
- flags : map [ string ]model.Flag {
170
- "footerColor" : {
171
- State : "ENABLED" ,
172
- DefaultVariant : "red" ,
173
- Variants : colorVariants ,
174
- Targeting : []byte (`{
171
+ flags : [ ]model.Flag { {
172
+ Key : "footerColor" ,
173
+ State : "ENABLED" ,
174
+ DefaultVariant : "red" ,
175
+ Variants : colorVariants ,
176
+ Targeting : []byte (`{
175
177
"if": [
176
178
{
177
179
"in": ["@faas.com", {
@@ -201,7 +203,7 @@ func TestFractionalEvaluation(t *testing.T) {
201
203
}, null
202
204
]
203
205
}` ),
204
- },
206
+ },
205
207
},
206
208
flagKey : "footerColor" ,
207
209
context : map [string ]any {
@@ -212,12 +214,12 @@ func TestFractionalEvaluation(t *testing.T) {
212
214
expectedReason : model .TargetingMatchReason ,
213
215
},
214
216
"non even split" : {
215
- flags : map [ string ]model.Flag {
216
- "headerColor" : {
217
- State : "ENABLED" ,
218
- DefaultVariant : "red" ,
219
- Variants : colorVariants ,
220
- Targeting : []byte (`{
217
+ flags : [ ]model.Flag { {
218
+ Key : "headerColor" ,
219
+ State : "ENABLED" ,
220
+ DefaultVariant : "red" ,
221
+ Variants : colorVariants ,
222
+ Targeting : []byte (`{
221
223
"if": [
222
224
{
223
225
"in": ["@faas.com", {
@@ -243,7 +245,7 @@ func TestFractionalEvaluation(t *testing.T) {
243
245
}, null
244
246
]
245
247
}` ),
246
- },
248
+ },
247
249
},
248
250
flagKey : "headerColor" ,
249
251
context : map [string ]any {
@@ -254,12 +256,12 @@ func TestFractionalEvaluation(t *testing.T) {
254
256
expectedReason : model .TargetingMatchReason ,
255
257
},
256
258
"fallback to default variant if no email provided" : {
257
- flags : map [ string ]model.Flag {
258
- "headerColor" : {
259
- State : "ENABLED" ,
260
- DefaultVariant : "red" ,
261
- Variants : colorVariants ,
262
- Targeting : []byte (`{
259
+ flags : [ ]model.Flag { {
260
+ Key : "headerColor" ,
261
+ State : "ENABLED" ,
262
+ DefaultVariant : "red" ,
263
+ Variants : colorVariants ,
264
+ Targeting : []byte (`{
263
265
"fractional": [
264
266
{"var": "email"},
265
267
[
@@ -280,7 +282,7 @@ func TestFractionalEvaluation(t *testing.T) {
280
282
]
281
283
]
282
284
}` ),
283
- },
285
+ },
284
286
},
285
287
flagKey : "headerColor" ,
286
288
context : map [string ]any {},
@@ -289,12 +291,12 @@ func TestFractionalEvaluation(t *testing.T) {
289
291
expectedReason : model .DefaultReason ,
290
292
},
291
293
"get variant for non-percentage weight values" : {
292
- flags : map [ string ]model.Flag {
293
- "headerColor" : {
294
- State : "ENABLED" ,
295
- DefaultVariant : "red" ,
296
- Variants : colorVariants ,
297
- Targeting : []byte (`{
294
+ flags : [ ]model.Flag { {
295
+ Key : "headerColor" ,
296
+ State : "ENABLED" ,
297
+ DefaultVariant : "red" ,
298
+ Variants : colorVariants ,
299
+ Targeting : []byte (`{
298
300
"fractional": [
299
301
{"var": "email"},
300
302
[
@@ -307,7 +309,7 @@ func TestFractionalEvaluation(t *testing.T) {
307
309
]
308
310
]
309
311
}` ),
310
- },
312
+ },
311
313
},
312
314
flagKey : "headerColor" ,
313
315
context : map [string ]any {
@@ -318,12 +320,12 @@ func TestFractionalEvaluation(t *testing.T) {
318
320
expectedReason : model .TargetingMatchReason ,
319
321
},
320
322
"get variant for non-specified weight values" : {
321
- flags : map [ string ]model.Flag {
322
- "headerColor" : {
323
- State : "ENABLED" ,
324
- DefaultVariant : "red" ,
325
- Variants : colorVariants ,
326
- Targeting : []byte (`{
323
+ flags : [ ]model.Flag { {
324
+ Key : "headerColor" ,
325
+ State : "ENABLED" ,
326
+ DefaultVariant : "red" ,
327
+ Variants : colorVariants ,
328
+ Targeting : []byte (`{
327
329
"fractional": [
328
330
{"var": "email"},
329
331
[
@@ -334,7 +336,7 @@ func TestFractionalEvaluation(t *testing.T) {
334
336
]
335
337
]
336
338
}` ),
337
- },
339
+ },
338
340
},
339
341
flagKey : "headerColor" ,
340
342
context : map [string ]any {
@@ -345,12 +347,12 @@ func TestFractionalEvaluation(t *testing.T) {
345
347
expectedReason : model .TargetingMatchReason ,
346
348
},
347
349
"default to targetingKey if no bucket key provided" : {
348
- flags : map [ string ]model.Flag {
349
- "headerColor" : {
350
- State : "ENABLED" ,
351
- DefaultVariant : "red" ,
352
- Variants : colorVariants ,
353
- Targeting : []byte (`{
350
+ flags : [ ]model.Flag { {
351
+ Key : "headerColor" ,
352
+ State : "ENABLED" ,
353
+ DefaultVariant : "red" ,
354
+ Variants : colorVariants ,
355
+ Targeting : []byte (`{
354
356
"fractional": [
355
357
[
356
358
"blue",
@@ -362,7 +364,7 @@ func TestFractionalEvaluation(t *testing.T) {
362
364
]
363
365
]
364
366
}` ),
365
- },
367
+ },
366
368
},
367
369
flagKey : "headerColor" ,
368
370
context : map [string ]any {
@@ -373,20 +375,20 @@ func TestFractionalEvaluation(t *testing.T) {
373
375
expectedReason : model .TargetingMatchReason ,
374
376
},
375
377
"missing email - parser should ignore nil/missing custom variables and continue" : {
376
- flags : map [ string ]model.Flag {
377
- "headerColor" : {
378
- State : "ENABLED" ,
379
- DefaultVariant : "red" ,
380
- Variants : colorVariants ,
381
- Targeting : []byte (
382
- `{
378
+ flags : [ ]model.Flag { {
379
+ Key : "headerColor" ,
380
+ State : "ENABLED" ,
381
+ DefaultVariant : "red" ,
382
+ Variants : colorVariants ,
383
+ Targeting : []byte (
384
+ `{
383
385
"fractional": [
384
386
{"var": "email"},
385
387
["red",50],
386
388
["blue",50]
387
389
]
388
390
}` ),
389
- },
391
+ },
390
392
},
391
393
flagKey : "headerColor" ,
392
394
context : map [string ]any {
@@ -438,12 +440,12 @@ func BenchmarkFractionalEvaluation(b *testing.B) {
438
440
var sources = []string {source }
439
441
ctx := context .Background ()
440
442
441
- flags := map [ string ]model.Flag {
442
- "headerColor" : {
443
- State : "ENABLED" ,
444
- DefaultVariant : "red" ,
445
- Variants : colorVariants ,
446
- Targeting : []byte (`{
443
+ flags := [ ]model.Flag { {
444
+ Key : "headerColor" ,
445
+ State : "ENABLED" ,
446
+ DefaultVariant : "red" ,
447
+ Variants : colorVariants ,
448
+ Targeting : []byte (`{
447
449
"if": [
448
450
{
449
451
"in": ["@faas.com", {
@@ -473,11 +475,11 @@ func BenchmarkFractionalEvaluation(b *testing.B) {
473
475
}, null
474
476
]
475
477
}` ),
476
- },
478
+ },
477
479
}
478
480
479
481
tests := map [string ]struct {
480
- flags map [ string ]model.Flag
482
+ flags [ ]model.Flag
481
483
flagKey string
482
484
context map [string ]any
483
485
expectedValue string
0 commit comments