1
1
package evaluation
2
2
3
3
import (
4
- "github.com/google/uuid"
5
-
6
4
"testing"
7
5
)
8
6
9
7
func TestSegment_Evaluate (t * testing.T ) {
10
8
type fields struct {
11
- Identifier string
12
- Name string
13
- CreatedAt * int64
14
- ModifiedAt * int64
15
- Environment * string
16
- Excluded StrSlice
17
- Included StrSlice
18
- Rules Clauses
19
- Tags []Tag
20
- Version int64
21
- }
22
- type args struct {
23
- target * Target
9
+ Identifier string
10
+ Excluded StrSlice
11
+ Included StrSlice
12
+ Rules SegmentRules
24
13
}
14
+
25
15
f := false
26
16
m := make (map [string ]interface {})
27
17
@@ -35,54 +25,28 @@ func TestSegment_Evaluate(t *testing.T) {
35
25
tests := []struct {
36
26
name string
37
27
fields fields
38
- args args
28
+ args Target
39
29
want bool
40
30
}{
41
- {name : "test included" , fields : struct {
42
- Identifier string
43
- Name string
44
- CreatedAt * int64
45
- ModifiedAt * int64
46
- Environment * string
47
- Excluded StrSlice
48
- Included StrSlice
49
- Rules Clauses
50
- Tags []Tag
51
- Version int64
52
- }{Identifier : "beta" , Name : "Beta users" , CreatedAt : nil , ModifiedAt : nil , Environment : nil , Excluded : nil ,
53
- Included : []string {"john" }, Rules : nil , Tags : nil , Version : 1 }, args : struct { target * Target }{target : & target }, want : true },
54
- {name : "test rules" , fields : struct {
55
- Identifier string
56
- Name string
57
- CreatedAt * int64
58
- ModifiedAt * int64
59
- Environment * string
60
- Excluded StrSlice
61
- Included StrSlice
62
- Rules Clauses
63
- Tags []Tag
64
- Version int64
65
- }{Identifier : "beta" , Name : "Beta users" , CreatedAt : nil , ModifiedAt : nil , Environment : nil , Excluded : nil ,
66
- Included : nil , Rules : []Clause {
67
- {
Attribute :
"email" ,
ID :
uuid .
New ().
String (),
Negate :
false ,
Op :
equalOperator ,
Value : []
string {
"[email protected] " }},
68
- }, Tags : nil , Version : 1 }, args : struct { target * Target }{target : & target }, want : true },
31
+ {name : "test target included by list" , fields : fields {Identifier : "beta" , Included : []string {"john" }}, args : target , want : true },
32
+ {name : "test target excluded by list" , fields : fields {Identifier : "beta" , Included : []string {"john" }, Excluded : []string {"john" }}, args : target , want : false },
33
+ {
name :
"test target included by rules" ,
fields :
fields {
Identifier :
"beta" ,
Rules : []
Clause {{
Attribute :
"email" ,
ID :
"1" ,
Op :
equalOperator ,
Value : []
string {
"[email protected] " }}}},
args :
target ,
want :
true },
34
+ {
name :
"test target not included by rules" ,
fields :
fields {
Identifier :
"beta" ,
Rules : []
Clause {{
Attribute :
"email" ,
ID :
"2" ,
Op :
equalOperator ,
Value : []
string {
"[email protected] " }}}},
args :
target ,
want :
false },
35
+ {name : "test target rules evaluating with OR" , fields : fields {Identifier : "beta" , Rules : []Clause {
36
+ {
Attribute :
"email" ,
ID :
"1" ,
Op :
equalOperator ,
Value : []
string {
"[email protected] " }},
37
+ {
Attribute :
"email" ,
ID :
"2" ,
Op :
equalOperator ,
Value : []
string {
"[email protected] " }},
38
+ }}, args : target , want : true },
69
39
}
70
40
for _ , tt := range tests {
71
41
val := tt
72
42
t .Run (val .name , func (t * testing.T ) {
73
43
s := Segment {
74
- Identifier : val .fields .Identifier ,
75
- Name : val .fields .Name ,
76
- CreatedAt : val .fields .CreatedAt ,
77
- ModifiedAt : val .fields .ModifiedAt ,
78
- Environment : val .fields .Environment ,
79
- Excluded : val .fields .Excluded ,
80
- Included : val .fields .Included ,
81
- Rules : val .fields .Rules ,
82
- Tags : val .fields .Tags ,
83
- Version : val .fields .Version ,
44
+ Identifier : val .fields .Identifier ,
45
+ Excluded : val .fields .Excluded ,
46
+ Included : val .fields .Included ,
47
+ Rules : val .fields .Rules ,
84
48
}
85
- if got := s .Evaluate (val .args . target ); got != val .want {
49
+ if got := s .Evaluate (& val .args ); got != val .want {
86
50
t .Errorf ("Evaluate() = %v, want %v" , got , val .want )
87
51
}
88
52
})
0 commit comments