@@ -20,7 +20,11 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
20
20
want flag.InternalFlag
21
21
}{
22
22
{
23
- name : "Simplest flag, no converter provided" ,
23
+ name : "Should return empty if flag dto is nil" ,
24
+ want : flag.InternalFlag {},
25
+ },
26
+ {
27
+ name : "[v0] Simplest flag, no converter provided" ,
24
28
d : dto.DTO {DTOv0 : dto.DTOv0 {
25
29
True : testconvert .Interface ("true" ),
26
30
False : testconvert .Interface ("false" ),
@@ -43,7 +47,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
43
47
},
44
48
},
45
49
{
46
- name : "Flag with percentage" ,
50
+ name : "[v0] Flag with percentage" ,
47
51
d : dto.DTO {DTOv0 : dto.DTOv0 {
48
52
Percentage : testconvert .Float64 (10 ),
49
53
True : testconvert .Interface ("true" ),
@@ -66,7 +70,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
66
70
},
67
71
},
68
72
{
69
- name : "Flag with 100 percentage" ,
73
+ name : "[v0] Flag with 100 percentage" ,
70
74
d : dto.DTO {DTOv0 : dto.DTOv0 {
71
75
Percentage : testconvert .Float64 (100 ),
72
76
True : testconvert .Interface ("true" ),
@@ -90,7 +94,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
90
94
},
91
95
},
92
96
{
93
- name : "Flag with rule not match" ,
97
+ name : "[v0] Flag with rule not match" ,
94
98
d : dto.DTO {DTOv0 : dto.DTOv0 {
95
99
Rule : testconvert .String ("key eq \" random\" " ),
96
100
True : testconvert .Interface ("true" ),
@@ -120,7 +124,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
120
124
},
121
125
},
122
126
{
123
- name : "Flag with rule match" ,
127
+ name : "[v0] Flag with rule match" ,
124
128
d : dto.DTO {DTOv0 : dto.DTOv0 {
125
129
Rule : testconvert .String ("key eq \" test-user\" " ),
126
130
True : testconvert .Interface ("true" ),
@@ -150,7 +154,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
150
154
},
151
155
},
152
156
{
153
- name : "Flag with rule match + 10% percentage" ,
157
+ name : "[v0] Flag with rule match + 10% percentage" ,
154
158
d : dto.DTO {DTOv0 : dto.DTOv0 {
155
159
Rule : testconvert .String ("key eq \" test-user\" " ),
156
160
Percentage : testconvert .Float64 (10 ),
@@ -181,7 +185,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
181
185
},
182
186
},
183
187
{
184
- name : "Flag with query + experimentation rollout" ,
188
+ name : "[v0] Flag with query + experimentation rollout" ,
185
189
d : dto.DTO {
186
190
DTOv0 : dto.DTOv0 {
187
191
Rule : testconvert .String ("key eq \" test-user\" " ),
@@ -228,7 +232,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
228
232
},
229
233
},
230
234
{
231
- name : "Flag with query + progressive rollout" ,
235
+ name : "[v0] Flag with query + progressive rollout" ,
232
236
d : dto.DTO {
233
237
DTOv0 : dto.DTOv0 {
234
238
Rule : testconvert .String ("key eq \" test-user\" " ),
@@ -283,7 +287,7 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
283
287
},
284
288
},
285
289
{
286
- name : "Flag without query + progressive rollout" ,
290
+ name : "[v0] Flag without query + progressive rollout" ,
287
291
d : dto.DTO {
288
292
DTOv0 : dto.DTOv0 {
289
293
True : testconvert .Interface ("true" ),
@@ -328,10 +332,121 @@ func TestConvertV0DtoToInternalFlag(t *testing.T) {
328
332
},
329
333
},
330
334
},
335
+ {
336
+ name : "[v1] Complete and complex flag v1" ,
337
+ d : dto.DTO {
338
+ DTOv1 : dto.DTOv1 {
339
+ Variations : & map [string ]* interface {}{
340
+ "VariationDefault" : testconvert .Interface (false ),
341
+ "VariationBar" : testconvert .Interface (false ),
342
+ "VariationFoo" : testconvert .Interface (true ),
343
+ },
344
+ Rules : & []flag.Rule {
345
+ {
346
+ Name : testconvert .String ("rule-number-1" ),
347
+ Query : testconvert .String ("key eq \" random-key\" " ),
348
+ Percentages : & map [string ]float64 {
349
+ "VariationBar" : 0 ,
350
+ "VariationFoo" : 100 ,
351
+ },
352
+ },
353
+ {
354
+ Name : testconvert .String ("rule-number-2" ),
355
+ Query : testconvert .String ("key eq \" other-random-key\" " ),
356
+ ProgressiveRollout : & flag.ProgressiveRollout {
357
+ Initial : & flag.ProgressiveRolloutStep {
358
+ Variation : testconvert .String ("VariationBar" ),
359
+ Percentage : testconvert .Float64 (0 ),
360
+ Date : testconvert .Time (time .Date (2021 , time .February , 1 , 10 , 10 , 10 , 10 , time .UTC )),
361
+ },
362
+ End : & flag.ProgressiveRolloutStep {
363
+ Variation : testconvert .String ("VariationFoo" ),
364
+ Percentage : testconvert .Float64 (100 ),
365
+ Date : testconvert .Time (time .Date (2021 , time .February , 2 , 10 , 10 , 10 , 10 , time .UTC )),
366
+ },
367
+ },
368
+ },
369
+ },
370
+ DefaultRule : & flag.Rule {
371
+ VariationResult : testconvert .String ("VariationDefault" ),
372
+ },
373
+ },
374
+ Rollout : & dto.Rollout {
375
+ CommonRollout : dto.CommonRollout {
376
+ Experimentation : & dto.ExperimentationDto {
377
+ Start : testconvert .Time (time .Date (2021 , time .February , 1 , 10 , 10 , 10 , 10 , time .UTC )),
378
+ End : testconvert .Time (time .Date (2021 , time .February , 2 , 10 , 10 , 10 , 10 , time .UTC )),
379
+ },
380
+ },
381
+ V1Rollout : dto.V1Rollout {Scheduled : & []flag.ScheduledStep {
382
+ {
383
+ InternalFlag : flag.InternalFlag {
384
+ Variations : & map [string ]* interface {}{
385
+ "VariationDefault" : testconvert .Interface (true ),
386
+ },
387
+ },
388
+ Date : testconvert .Time (time .Date (2021 , time .February , 2 , 10 , 10 , 10 , 10 , time .UTC )),
389
+ },
390
+ }},
391
+ },
392
+ },
393
+ want : flag.InternalFlag {
394
+ Variations : & map [string ]* interface {}{
395
+ "VariationDefault" : testconvert .Interface (false ),
396
+ "VariationBar" : testconvert .Interface (false ),
397
+ "VariationFoo" : testconvert .Interface (true ),
398
+ },
399
+ Rules : & []flag.Rule {
400
+ {
401
+ Name : testconvert .String ("rule-number-1" ),
402
+ Query : testconvert .String ("key eq \" random-key\" " ),
403
+ Percentages : & map [string ]float64 {
404
+ "VariationBar" : 0 ,
405
+ "VariationFoo" : 100 ,
406
+ },
407
+ },
408
+ {
409
+ Name : testconvert .String ("rule-number-2" ),
410
+ Query : testconvert .String ("key eq \" other-random-key\" " ),
411
+ ProgressiveRollout : & flag.ProgressiveRollout {
412
+ Initial : & flag.ProgressiveRolloutStep {
413
+ Variation : testconvert .String ("VariationBar" ),
414
+ Percentage : testconvert .Float64 (0 ),
415
+ Date : testconvert .Time (time .Date (2021 , time .February , 1 , 10 , 10 , 10 , 10 , time .UTC )),
416
+ },
417
+ End : & flag.ProgressiveRolloutStep {
418
+ Variation : testconvert .String ("VariationFoo" ),
419
+ Percentage : testconvert .Float64 (100 ),
420
+ Date : testconvert .Time (time .Date (2021 , time .February , 2 , 10 , 10 , 10 , 10 , time .UTC )),
421
+ },
422
+ },
423
+ },
424
+ },
425
+ DefaultRule : & flag.Rule {
426
+ VariationResult : testconvert .String ("VariationDefault" ),
427
+ },
428
+ Rollout : & flag.Rollout {
429
+ Experimentation : & flag.ExperimentationRollout {
430
+ Start : testconvert .Time (time .Date (2021 , time .February , 1 , 10 , 10 , 10 , 10 , time .UTC )),
431
+ End : testconvert .Time (time .Date (2021 , time .February , 2 , 10 , 10 , 10 , 10 , time .UTC )),
432
+ },
433
+ Scheduled : & []flag.ScheduledStep {
434
+ {
435
+ InternalFlag : flag.InternalFlag {
436
+ Variations : & map [string ]* interface {}{
437
+ "VariationDefault" : testconvert .Interface (true ),
438
+ },
439
+ },
440
+ Date : testconvert .Time (time .Date (2021 , time .February , 2 , 10 , 10 , 10 , 10 , time .UTC )),
441
+ },
442
+ },
443
+ },
444
+ },
445
+ },
331
446
}
332
447
for _ , tt := range tests {
333
448
t .Run (tt .name , func (t * testing.T ) {
334
- assert .Equal (t , tt .want , dto . ConvertV0DtoToInternalFlag ( tt .d , false ))
449
+ assert .Equal (t , tt .want , tt .d . Convert ( ))
335
450
})
336
451
}
337
452
}
0 commit comments