66
77 "github.com/splitio/go-split-commons/v9/dtos"
88 "github.com/splitio/go-split-commons/v9/storage/inmemory"
9+ "github.com/stretchr/testify/assert"
910)
1011
1112func TestOptimizedMode (t * testing.T ) {
@@ -24,32 +25,55 @@ func TestOptimizedMode(t *testing.T) {
2425 }
2526
2627 toLog , toListener := optimized .Apply ([]dtos.Impression {imp })
28+ assert .Equal (t , 1 , len (toLog ), "Should have 1 to log" )
29+ assert .Equal (t , 1 , len (toListener ), "Should have 1 to listener" )
2730
28- if len (toLog ) != 1 || len (toListener ) != 1 {
29- t .Error ("Should have 1 to log" )
31+ assert .Equal (t , 0 , len (counter .impressionsCounts ), "Should not have counts" )
32+
33+ toLog , toListener = optimized .Apply ([]dtos.Impression {imp })
34+
35+ assert .Equal (t , 0 , len (toLog ), "Should have 0 to log" )
36+ assert .Equal (t , 1 , len (toListener ), "Should have 1 to listener" )
37+
38+ rawCounts := counter .PopAll ()
39+ assert .Equal (t , 1 , len (rawCounts ), "Should have counts" )
40+ for key , counts := range counter .PopAll () {
41+ assert .Equal (t , "feature-test" , key .FeatureName , "Feature should be feature-test" )
42+ assert .Equal (t , 1 , counts , "It should be tracked only once" )
3043 }
44+ }
3145
32- if len (counter .impressionsCounts ) != 0 {
33- t .Error ("Should not have counts" )
46+ func TestOptimizedModeWithProperties (t * testing.T ) {
47+ observer , _ := NewImpressionObserver (5000 )
48+ counter := NewImpressionsCounter ()
49+ runtimeTelemetry , _ := inmemory .NewTelemetryStorage ()
50+ optimized := NewOptimizedImpl (observer , counter , runtimeTelemetry , true )
51+ imp := dtos.Impression {
52+ BucketingKey : "someBuck" ,
53+ ChangeNumber : 123 ,
54+ KeyName : "someKey" ,
55+ Label : "someLabel" ,
56+ Time : time .Now ().UTC ().UnixNano (),
57+ Treatment : "on" ,
58+ FeatureName : "feature-test" ,
59+ Properties : "{'hello':'world'}" ,
3460 }
3561
62+ toLog , toListener := optimized .Apply ([]dtos.Impression {imp })
63+
64+ assert .Equal (t , 1 , len (toLog ), "Should have 1 to log" )
65+ assert .Equal (t , 1 , len (toListener ), "Should have 1 to listener" )
66+
3667 toLog , toListener = optimized .Apply ([]dtos.Impression {imp })
3768
38- if len (toLog ) != 0 || len (toListener ) != 1 {
39- t .Error ("Should not have to log" )
40- }
69+ assert .Equal (t , 1 , len (toLog ), "toLog should be 1" )
70+ assert .Equal (t , 1 , len (toListener ), "toListener should be 1" )
4171
4272 rawCounts := counter .PopAll ()
43- if len (rawCounts ) != 1 {
44- t .Error ("Should have counts" )
45- }
73+ assert .Equal (t , 0 , len (rawCounts ), "Should doesn't have counts" )
4674 for key , counts := range counter .PopAll () {
47- if key .FeatureName != "feature-test" {
48- t .Error ("Feature should be feature-test" )
49- }
50- if counts != 1 {
51- t .Error ("It should be tracked only once" )
52- }
75+ assert .Equal (t , "feature-test" , key .FeatureName , "Feature should be feature-test" )
76+ assert .Equal (t , 1 , counts , "It should be tracked empty" )
5377 }
5478}
5579
@@ -70,13 +94,8 @@ func TestApplySingleOptimized(t *testing.T) {
7094
7195 toLog := optimized .ApplySingle (& imp )
7296
73- if ! toLog {
74- t .Error ("Should be true" )
75- }
76-
97+ assert .True (t , toLog , "Should be true" )
7798 toLog = optimized .ApplySingle (& imp )
7899
79- if toLog {
80- t .Error ("Should be false" )
81- }
100+ assert .False (t , toLog , "Should be false" )
82101}
0 commit comments