@@ -30,36 +30,64 @@ func Test_AssignBlankSubject(t *testing.T) {
3030 _ , err := client .GetStringAssignment ("experiment-1" , "" , Attributes {}, "" )
3131 assert .Error (t , err )
3232}
33+
3334func Test_LogAssignment (t * testing.T ) {
34- var mockLogger = new (mockLogger )
35- mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Return ()
35+ tests := []struct {
36+ name string
37+ doLog * bool
38+ expectedCalls int
39+ }{
40+ {
41+ name : "DoLog key is absent" ,
42+ doLog : nil ,
43+ expectedCalls : 1 ,
44+ },
45+ {
46+ name : "DoLog key is present but false" ,
47+ doLog : & []bool {false }[0 ],
48+ expectedCalls : 0 ,
49+ },
50+ {
51+ name : "DoLog key is present and true" ,
52+ doLog : & []bool {true }[0 ],
53+ expectedCalls : 1 ,
54+ },
55+ }
3656
37- config := configResponse {
38- Flags : map [string ]flagConfiguration {
39- "experiment-key-1" : flagConfiguration {
40- Key : "experiment-key-1" ,
41- Enabled : true ,
42- TotalShards : 10000 ,
43- VariationType : stringVariation ,
44- Variations : map [string ]variation {
45- "control" : variation {
46- Key : "control" ,
47- Value : "control" ,
48- },
49- },
50- Allocations : []allocation {
51- {
52- Key : "allocation-key" ,
53- Splits : []split {
57+ for _ , tt := range tests {
58+ t .Run (tt .name , func (t * testing.T ) {
59+ var mockLogger = new (mockLogger )
60+ mockLogger .Mock .On ("LogAssignment" , mock .Anything ).Return ()
61+
62+ config := configResponse {
63+ Flags : map [string ]flagConfiguration {
64+ "experiment-key-1" : flagConfiguration {
65+ Key : "experiment-key-1" ,
66+ Enabled : true ,
67+ TotalShards : 10000 ,
68+ VariationType : stringVariation ,
69+ Variations : map [string ]variation {
70+ "control" : variation {
71+ Key : "control" ,
72+ Value : "control" ,
73+ },
74+ },
75+ Allocations : []allocation {
5476 {
55- VariationKey : "control" ,
56- Shards : []shard {
77+ Key : "allocation-key" ,
78+ DoLog : tt .doLog ,
79+ Splits : []split {
5780 {
58- Salt : "" ,
59- Ranges : []shardRange {
81+ VariationKey : "control " ,
82+ Shards : []shard {
6083 {
61- Start : 0 ,
62- End : 10000 ,
84+ Salt : "" ,
85+ Ranges : []shardRange {
86+ {
87+ Start : 0 ,
88+ End : 10000 ,
89+ },
90+ },
6391 },
6492 },
6593 },
@@ -68,17 +96,18 @@ func Test_LogAssignment(t *testing.T) {
6896 },
6997 },
7098 },
71- },
72- }}
99+ }
73100
74- client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
101+ client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
75102
76- assignment , err := client .GetStringAssignment ("experiment-key-1" , "user-1" , Attributes {}, "" )
77- expected := "control"
103+ assignment , err := client .GetStringAssignment ("experiment-key-1" , "user-1" , Attributes {}, "" )
104+ expected := "control"
78105
79- assert .Nil (t , err )
80- assert .Equal (t , expected , assignment )
81- mockLogger .AssertNumberOfCalls (t , "LogAssignment" , 1 )
106+ assert .Nil (t , err )
107+ assert .Equal (t , expected , assignment )
108+ mockLogger .AssertNumberOfCalls (t , "LogAssignment" , tt .expectedCalls )
109+ })
110+ }
82111}
83112
84113func Test_client_loggerIsCalledWithProperBanditEvent (t * testing.T ) {
0 commit comments