@@ -17,7 +17,7 @@ func Test_AssignBlankExperiment(t *testing.T) {
17
17
client := newEppoClient (mockConfigRequestor , mockLogger )
18
18
19
19
assert .Panics (t , func () {
20
- _ , err := client .GetAssignment ("subject-1" , "" , dictionary {})
20
+ _ , err := client .GetStringAssignment ("subject-1" , "" , dictionary {})
21
21
if err != nil {
22
22
log .Println (err )
23
23
}
@@ -30,7 +30,7 @@ func Test_AssignBlankSubject(t *testing.T) {
30
30
client := newEppoClient (mockConfigRequestor , mockLogger )
31
31
32
32
assert .Panics (t , func () {
33
- _ , err := client .GetAssignment ("" , "experiment-1" , dictionary {})
33
+ _ , err := client .GetStringAssignment ("" , "experiment-1" , dictionary {})
34
34
if err != nil {
35
35
log .Println (err )
36
36
}
@@ -40,7 +40,7 @@ func Test_AssignBlankSubject(t *testing.T) {
40
40
func Test_SubjectNotInSample (t * testing.T ) {
41
41
var mockLogger = new (mockLogger )
42
42
var mockConfigRequestor = new (mockConfigRequestor )
43
- overrides := make (dictionary )
43
+ overrides := make (map [ string ] Value )
44
44
var mockVariations = []Variation {
45
45
{Name : "control" , Value : String ("control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
46
46
}
@@ -62,7 +62,7 @@ func Test_SubjectNotInSample(t *testing.T) {
62
62
63
63
client := newEppoClient (mockConfigRequestor , mockLogger )
64
64
65
- assignment , err := client .GetAssignment ("user-1" , "experiment-key-1" , dictionary {})
65
+ assignment , err := client .GetStringAssignment ("user-1" , "experiment-key-1" , dictionary {})
66
66
67
67
assert .Equal (t , "" , assignment )
68
68
assert .NotNil (t , err )
@@ -73,7 +73,7 @@ func Test_LogAssignment(t *testing.T) {
73
73
mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Return ()
74
74
75
75
var mockConfigRequestor = new (mockConfigRequestor )
76
- overrides := make (dictionary )
76
+ overrides := make (map [ string ] Value )
77
77
78
78
var mockVariations = []Variation {
79
79
{Name : "control" , Value : String ("control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
@@ -95,20 +95,20 @@ func Test_LogAssignment(t *testing.T) {
95
95
96
96
client := newEppoClient (mockConfigRequestor , mockLogger )
97
97
98
- assignment , err := client .GetAssignment ("user-1" , "experiment-key-1" , dictionary {})
98
+ assignment , err := client .GetStringAssignment ("user-1" , "experiment-key-1" , dictionary {})
99
99
expected := "control"
100
100
101
101
assert .Nil (t , err )
102
102
assert .Equal (t , expected , assignment )
103
103
mockLogger .AssertNumberOfCalls (t , "LogAssignment" , 1 )
104
104
}
105
105
106
- func Test_GetAssignmentHandlesLoggingPanic (t * testing.T ) {
106
+ func Test_GetStringAssignmentHandlesLoggingPanic (t * testing.T ) {
107
107
var mockLogger = new (mockLogger )
108
108
mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Panic ("logging panic" )
109
109
110
110
var mockConfigRequestor = new (mockConfigRequestor )
111
- overrides := make (dictionary )
111
+ overrides := make (map [ string ] Value )
112
112
113
113
var mockVariations = []Variation {
114
114
{Name : "control" , Value : String ("control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
@@ -130,7 +130,7 @@ func Test_GetAssignmentHandlesLoggingPanic(t *testing.T) {
130
130
131
131
client := newEppoClient (mockConfigRequestor , mockLogger )
132
132
133
- assignment , err := client .GetAssignment ("user-1" , "experiment-key-1" , dictionary {})
133
+ assignment , err := client .GetStringAssignment ("user-1" , "experiment-key-1" , dictionary {})
134
134
expected := "control"
135
135
136
136
assert .Nil (t , err )
@@ -144,7 +144,7 @@ func Test_AssignSubjectWithAttributesAndRules(t *testing.T) {
144
144
var matchesEmailCondition = condition {Operator : "MATCHES" , Value : ".*@eppo.com" , Attribute : "email" }
145
145
var textRule = rule {AllocationKey : defaultAllocationKey , Conditions : []condition {matchesEmailCondition }}
146
146
var mockConfigRequestor = new (mockConfigRequestor )
147
- var overrides = make (dictionary )
147
+ overrides : = make (map [ string ] Value )
148
148
var mockVariations = []Variation {
149
149
{Name : "control" , Value : String ("control" ), ShardRange : shardRange {Start : 0 , End : 10000 }},
150
150
}
@@ -181,42 +181,77 @@ func Test_AssignSubjectWithAttributesAndRules(t *testing.T) {
181
181
client := newEppoClient (mockConfigRequestor , mockLogger )
182
182
183
183
for _ , tt := range tests {
184
- assignment , _ := client .GetAssignment (tt .a , tt .b , tt .c )
184
+ assignment , _ := client .GetStringAssignment (tt .a , tt .b , tt .c )
185
185
186
186
assert .Equal (t , tt .want , assignment )
187
187
}
188
188
}
189
189
190
190
func Test_WithSubjectInOverrides (t * testing.T ) {
191
- var mockLogger = new (mockLogger )
192
- mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Return ()
193
-
194
- var mockConfigRequestor = new (mockConfigRequestor )
195
- var mockVariations = []Variation {
196
- {Name : "control" , ShardRange : shardRange {Start : 0 , End : 100 }},
197
- }
198
- var overrides = make (dictionary )
199
- overrides ["d6d7705392bc7af633328bea8c4c6904" ] = "override-variation"
200
- var allocations = make (map [string ]Allocation )
201
- allocations [defaultAllocationKey ] = Allocation {
202
- PercentExposure : 1 ,
203
- Variations : mockVariations ,
204
- }
205
- var mockResult = experimentConfiguration {
206
- Name : "recommendation_algo" ,
207
- Enabled : true ,
208
- SubjectShards : 1000 ,
209
- Overrides : overrides ,
210
- Rules : []rule {textRule },
191
+ var tests = []struct {
192
+ name string
193
+ inputVariationOverrideValue Value
194
+ inputValueType ValueType
195
+ want Value
196
+ }{
197
+ {"string override" , String ("variation-value" ), StringType , String ("variation-value" )},
198
+ {"numeric override" , Numeric (5 ), NumericType , Numeric (5 )},
199
+ {"boolean override" , Bool (true ), BoolType , Bool (true )},
211
200
}
212
201
213
- mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
214
-
215
- client := newEppoClient (mockConfigRequestor , mockLogger )
202
+ for _ , tt := range tests {
203
+ t .Run (tt .name , func (t * testing.T ) {
204
+
205
+ var mockLogger = new (mockLogger )
206
+ mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Return ()
207
+
208
+ var mockConfigRequestor = new (mockConfigRequestor )
209
+ var mockVariations = []Variation {
210
+ {Name : "control" , ShardRange : shardRange {Start : 0 , End : 100 }},
211
+ }
212
+ overrides := make (map [string ]Value )
213
+ overrides ["d6d7705392bc7af633328bea8c4c6904" ] = tt .inputVariationOverrideValue
214
+ var allocations = make (map [string ]Allocation )
215
+ allocations [defaultAllocationKey ] = Allocation {
216
+ PercentExposure : 1 ,
217
+ Variations : mockVariations ,
218
+ }
219
+ var mockResult = experimentConfiguration {
220
+ Name : "recommendation_algo" ,
221
+ Enabled : true ,
222
+ SubjectShards : 1000 ,
223
+ Overrides : overrides ,
224
+ Rules : []rule {textRule },
225
+ }
226
+
227
+ mockConfigRequestor .Mock .On ("GetConfiguration" , "experiment-key-1" ).Return (mockResult , nil )
228
+
229
+ client := newEppoClient (mockConfigRequestor , mockLogger )
230
+
231
+ switch tt .inputValueType {
232
+ case StringType :
233
+ assignment , _ := client .GetStringAssignment ("user-1" , "experiment-key-1" , dictionary {})
234
+
235
+ if assignment != tt .want .stringValue {
236
+ t .Errorf ("got %s, want %s" , assignment , tt .want .stringValue )
237
+ }
238
+ case NumericType :
239
+ assignment , _ := client .GetNumericAssignment ("user-1" , "experiment-key-1" , dictionary {})
240
+
241
+ if assignment != tt .want .numericValue {
242
+ t .Errorf ("got %T, want %T" , assignment , tt .want .numericValue )
243
+ }
244
+ case BoolType :
245
+ assignment , _ := client .GetBoolAssignment ("user-1" , "experiment-key-1" , dictionary {})
246
+
247
+ if assignment != tt .want .boolValue {
248
+ t .Errorf ("got %t, want %t" , assignment , tt .want .boolValue )
249
+ }
250
+
251
+ }
252
+ })
253
+ }
216
254
217
- expected := "override-variation"
218
- assignment , _ := client .GetAssignment ("user-1" , "experiment-key-1" , dictionary {})
219
- assert .Equal (t , expected , assignment )
220
255
}
221
256
222
257
func Test_WithSubjectInOverridesExpDisabled (t * testing.T ) {
@@ -227,8 +262,8 @@ func Test_WithSubjectInOverridesExpDisabled(t *testing.T) {
227
262
var mockVariations = []Variation {
228
263
{Name : "control" , ShardRange : shardRange {Start : 0 , End : 100 }},
229
264
}
230
- var overrides = make (dictionary )
231
- overrides ["d6d7705392bc7af633328bea8c4c6904" ] = "override-variation"
265
+ overrides : = make (map [ string ] Value )
266
+ overrides ["d6d7705392bc7af633328bea8c4c6904" ] = String ( "override-variation" )
232
267
var allocations = make (map [string ]Allocation )
233
268
allocations [defaultAllocationKey ] = Allocation {
234
269
PercentExposure : 1 ,
@@ -248,7 +283,7 @@ func Test_WithSubjectInOverridesExpDisabled(t *testing.T) {
248
283
client := newEppoClient (mockConfigRequestor , mockLogger )
249
284
250
285
expected := "override-variation"
251
- assignment , err := client .GetAssignment ("user-1" , "experiment-key-1" , dictionary {})
286
+ assignment , err := client .GetStringAssignment ("user-1" , "experiment-key-1" , dictionary {})
252
287
253
288
assert .Nil (t , err )
254
289
assert .Equal (t , expected , assignment )
@@ -264,7 +299,7 @@ func Test_WithNullExpConfig(t *testing.T) {
264
299
client := newEppoClient (mockConfigRequestor , mockLogger )
265
300
266
301
expected := ""
267
- assignment , err := client .GetAssignment ("user-1" , "experiment-key-1" , dictionary {})
302
+ assignment , err := client .GetStringAssignment ("user-1" , "experiment-key-1" , dictionary {})
268
303
269
304
assert .NotNil (t , err )
270
305
assert .Equal (t , expected , assignment )
0 commit comments