@@ -30,36 +30,64 @@ func Test_AssignBlankSubject(t *testing.T) {
30
30
_ , err := client .GetStringAssignment ("experiment-1" , "" , Attributes {}, "" )
31
31
assert .Error (t , err )
32
32
}
33
+
33
34
func 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
+ }
36
56
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 {
54
76
{
55
- VariationKey : "control" ,
56
- Shards : []shard {
77
+ Key : "allocation-key" ,
78
+ DoLog : tt .doLog ,
79
+ Splits : []split {
57
80
{
58
- Salt : "" ,
59
- Ranges : []shardRange {
81
+ VariationKey : "control " ,
82
+ Shards : []shard {
60
83
{
61
- Start : 0 ,
62
- End : 10000 ,
84
+ Salt : "" ,
85
+ Ranges : []shardRange {
86
+ {
87
+ Start : 0 ,
88
+ End : 10000 ,
89
+ },
90
+ },
63
91
},
64
92
},
65
93
},
@@ -68,17 +96,18 @@ func Test_LogAssignment(t *testing.T) {
68
96
},
69
97
},
70
98
},
71
- },
72
- }}
99
+ }
73
100
74
- client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
101
+ client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
75
102
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"
78
105
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
+ }
82
111
}
83
112
84
113
func Test_client_loggerIsCalledWithProperBanditEvent (t * testing.T ) {
0 commit comments