7
7
"github.com/stretchr/testify/mock"
8
8
)
9
9
10
+ var defaultAllocationKey = "allocation-key"
11
+ var defaultRule = rule {Conditions : []condition {}, AllocationKey : defaultAllocationKey }
12
+
10
13
func Test_AssignBlankExperiment (t * testing.T ) {
11
14
var mockConfigRequestor = new (mockConfigRequestor )
12
15
var mockLogger = new (mockLogger )
@@ -28,16 +31,21 @@ func Test_SubjectNotInSample(t *testing.T) {
28
31
var mockConfigRequestor = new (mockConfigRequestor )
29
32
overrides := make (dictionary )
30
33
var mockVariations = []Variation {
31
- {Name : "control" , ShardRange : shardRange {Start : 0 , End : 10000 }},
34
+ {Name : "control" , Value : String ( "control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
32
35
}
33
- mockResult := experimentConfiguration {
34
- Name : "recommendation_algo" ,
36
+ var allocations = make ( map [ string ] Allocation )
37
+ allocations [ defaultAllocationKey ] = Allocation {
35
38
PercentExposure : 0 ,
36
- Enabled : true ,
37
- SubjectShards : 1000 ,
38
- Overrides : overrides ,
39
39
Variations : mockVariations ,
40
40
}
41
+ mockResult := experimentConfiguration {
42
+ Name : "recommendation_algo" ,
43
+ Enabled : true ,
44
+ SubjectShards : 1000 ,
45
+ Overrides : overrides ,
46
+ Allocations : allocations ,
47
+ Rules : []rule {defaultRule },
48
+ }
41
49
42
50
mockConfigRequestor .Mock .On ("GetConfiguration" , mock .Anything ).Return (mockResult , nil )
43
51
@@ -57,16 +65,21 @@ func Test_LogAssignment(t *testing.T) {
57
65
overrides := make (dictionary )
58
66
59
67
var mockVariations = []Variation {
60
- {Name : "control" , ShardRange : shardRange {Start : 0 , End : 10000 }},
68
+ {Name : "control" , Value : String ( "control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
61
69
}
62
- mockResult := experimentConfiguration {
63
- Name : "recommendation_algo" ,
64
- PercentExposure : 100 ,
65
- Enabled : true ,
66
- SubjectShards : 1000 ,
67
- Overrides : overrides ,
70
+ var allocations = make (map [string ]Allocation )
71
+ allocations [defaultAllocationKey ] = Allocation {
72
+ PercentExposure : 1 ,
68
73
Variations : mockVariations ,
69
74
}
75
+ mockResult := experimentConfiguration {
76
+ Name : "recommendation_algo" ,
77
+ Enabled : true ,
78
+ SubjectShards : 1000 ,
79
+ Overrides : overrides ,
80
+ Allocations : allocations ,
81
+ Rules : []rule {defaultRule },
82
+ }
70
83
mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
71
84
72
85
client := newEppoClient (mockConfigRequestor , mockLogger )
@@ -87,16 +100,21 @@ func Test_GetAssignmentHandlesLoggingPanic(t *testing.T) {
87
100
overrides := make (dictionary )
88
101
89
102
var mockVariations = []Variation {
90
- {Name : "control" , ShardRange : shardRange {Start : 0 , End : 10000 }},
103
+ {Name : "control" , Value : String ( "control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
91
104
}
92
- mockResult := experimentConfiguration {
93
- Name : "recommendation_algo" ,
94
- PercentExposure : 100 ,
95
- Enabled : true ,
96
- SubjectShards : 1000 ,
97
- Overrides : overrides ,
105
+ var allocations = make (map [string ]Allocation )
106
+ allocations [defaultAllocationKey ] = Allocation {
107
+ PercentExposure : 1 ,
98
108
Variations : mockVariations ,
99
109
}
110
+ mockResult := experimentConfiguration {
111
+ Name : "recommendation_algo" ,
112
+ Enabled : true ,
113
+ SubjectShards : 1000 ,
114
+ Overrides : overrides ,
115
+ Allocations : allocations ,
116
+ Rules : []rule {defaultRule },
117
+ }
100
118
mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
101
119
102
120
client := newEppoClient (mockConfigRequestor , mockLogger )
@@ -113,20 +131,24 @@ func Test_AssignSubjectWithAttributesAndRules(t *testing.T) {
113
131
mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Return ()
114
132
115
133
var matchesEmailCondition = condition {Operator : "MATCHES" , Value : ".*@eppo.com" , Attribute : "email" }
116
- var textRule = rule {Conditions : []condition {matchesEmailCondition }}
134
+ var textRule = rule {AllocationKey : defaultAllocationKey , Conditions : []condition {matchesEmailCondition }}
117
135
var mockConfigRequestor = new (mockConfigRequestor )
118
136
var overrides = make (dictionary )
119
137
var mockVariations = []Variation {
120
- {Name : "control" , ShardRange : shardRange {Start : 0 , End : 10000 }},
138
+ {Name : "control" , Value : String ( "control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
121
139
}
122
- var mockResult = experimentConfiguration {
123
- Name : "recommendation_algo" ,
124
- PercentExposure : 100 ,
125
- Enabled : true ,
126
- SubjectShards : 1000 ,
127
- Overrides : overrides ,
140
+ var allocations = make (map [string ]Allocation )
141
+ allocations [defaultAllocationKey ] = Allocation {
142
+ PercentExposure : 1 ,
128
143
Variations : mockVariations ,
129
- Rules : []rule {textRule },
144
+ }
145
+ var mockResult = experimentConfiguration {
146
+ Name : "recommendation_algo" ,
147
+ Enabled : true ,
148
+ SubjectShards : 1000 ,
149
+ Overrides : overrides ,
150
+ Rules : []rule {textRule },
151
+ Allocations : allocations ,
130
152
}
131
153
mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
132
154
@@ -164,14 +186,17 @@ func Test_WithSubjectInOverrides(t *testing.T) {
164
186
}
165
187
var overrides = make (dictionary )
166
188
overrides ["d6d7705392bc7af633328bea8c4c6904" ] = "override-variation"
167
- var mockResult = experimentConfiguration {
168
- Name : "recommendation_algo" ,
169
- PercentExposure : 100 ,
170
- Enabled : true ,
171
- SubjectShards : 1000 ,
172
- Overrides : overrides ,
189
+ var allocations = make (map [string ]Allocation )
190
+ allocations [defaultAllocationKey ] = Allocation {
191
+ PercentExposure : 1 ,
173
192
Variations : mockVariations ,
174
- Rules : []rule {textRule },
193
+ }
194
+ var mockResult = experimentConfiguration {
195
+ Name : "recommendation_algo" ,
196
+ Enabled : true ,
197
+ SubjectShards : 1000 ,
198
+ Overrides : overrides ,
199
+ Rules : []rule {textRule },
175
200
}
176
201
177
202
mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
@@ -193,14 +218,18 @@ func Test_WithSubjectInOverridesExpDisabled(t *testing.T) {
193
218
}
194
219
var overrides = make (dictionary )
195
220
overrides ["d6d7705392bc7af633328bea8c4c6904" ] = "override-variation"
196
- var mockResult = experimentConfiguration {
197
- Name : "recommendation_algo" ,
198
- PercentExposure : 100 ,
199
- Enabled : false ,
200
- SubjectShards : 1000 ,
201
- Overrides : overrides ,
221
+ var allocations = make (map [string ]Allocation )
222
+ allocations [defaultAllocationKey ] = Allocation {
223
+ PercentExposure : 1 ,
202
224
Variations : mockVariations ,
203
- Rules : []rule {textRule },
225
+ }
226
+ var mockResult = experimentConfiguration {
227
+ Name : "recommendation_algo" ,
228
+ Enabled : false ,
229
+ SubjectShards : 1000 ,
230
+ Overrides : overrides ,
231
+ Allocations : allocations ,
232
+ Rules : []rule {textRule },
204
233
}
205
234
206
235
mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
0 commit comments