@@ -3,7 +3,7 @@ package evaluation
3
3
import (
4
4
"encoding/json"
5
5
6
- "github.com/drone/ff-golang-server-sdk.v1 /types"
6
+ "github.com/drone/ff-golang-server-sdk.v0 /types"
7
7
8
8
"reflect"
9
9
"strconv"
@@ -436,10 +436,21 @@ func TestFeatureConfig_IntVariation(t *testing.T) {
436
436
437
437
func TestServingRules_GetVariationName (t * testing.T ) {
438
438
439
+ dev := "dev"
439
440
harness := "Harness"
440
441
onVariationIdentifier := "v1"
441
442
offVariationIdentifier := "v2"
442
443
444
+ segment := & Segment {
445
+ Identifier : "beta" ,
446
+ Name : "beta" ,
447
+ Environment : & dev ,
448
+ Included : []string {harness },
449
+ Rules : nil ,
450
+ Tags : nil ,
451
+ Version : 1 ,
452
+ }
453
+
443
454
target := & Target {
444
455
Identifier : harness ,
445
456
Name : & harness ,
@@ -491,6 +502,24 @@ func TestServingRules_GetVariationName(t *testing.T) {
491
502
Distribution * Distribution
492
503
Variation * string
493
504
}{Distribution : nil , Variation : & onVariationIdentifier }}, want : offVariationIdentifier },
505
+ //
506
+ {name : "segment match" , sr : []ServingRule {
507
+ {Clauses : []Clause {
508
+ {Op : segmentMatchOperator , Value : []string {
509
+ segment .Identifier ,
510
+ }},
511
+ }, Priority : 0 , RuleID : uuid .NewString (), Serve : struct {
512
+ Distribution * Distribution
513
+ Variation * string
514
+ }{Distribution : nil , Variation : & offVariationIdentifier }},
515
+ }, args : struct {
516
+ target * Target
517
+ segments Segments
518
+ defaultServe Serve
519
+ }{target : target , segments : Segments {segment .Identifier : segment }, defaultServe : struct {
520
+ Distribution * Distribution
521
+ Variation * string
522
+ }{Distribution : nil , Variation : & onVariationIdentifier }}, want : offVariationIdentifier },
494
523
}
495
524
for _ , tt := range tests {
496
525
val := tt
@@ -618,31 +647,24 @@ func TestClause_Evaluate(t *testing.T) {
618
647
args args
619
648
want bool
620
649
}{
621
- {name : "segment match operator" , fields : struct {
650
+ {name : "segment match operator (include) " , fields : struct {
622
651
Attribute string
623
652
ID string
624
653
Negate bool
625
654
Op string
626
655
Value []string
627
- }{Attribute : "identifier" , ID : uuid . New (). String (), Negate : false , Op : segmentMatchOperator , Value : []string {"beta" }},
656
+ }{Op : segmentMatchOperator , Value : []string {"beta" }},
628
657
args : struct {
629
658
target * Target
630
659
segments Segments
631
660
operator types.ValueType
632
661
}{target : & target , segments : map [string ]* Segment {
633
662
"beta" : {
634
- Identifier : "beta" ,
635
- Name : "Beta users" ,
636
- CreatedAt : nil ,
637
- ModifiedAt : nil ,
638
- Environment : nil ,
639
- Excluded : nil ,
640
- Included : []string {target .Identifier },
641
- Rules : nil ,
642
- Tags : nil ,
643
- Version : 0 ,
663
+ Identifier : "beta" ,
664
+ Name : "Beta users" ,
665
+ Included : []string {target .Identifier },
644
666
},
645
- },
operator :
types . String ( "[email protected] " ) },
want :
true },
667
+ }, operator : nil }, want : true },
646
668
}
647
669
for _ , tt := range tests {
648
670
val := tt
0 commit comments