@@ -18,12 +18,14 @@ func TestSerializeEventFromProtoConsistency(t *testing.T) {
1818 type event struct {
1919 attributes map [string ]any
2020 trails []string
21+ event_type string
2122 }
2223 tests := []struct {
2324 name string
2425 event1 event
2526 event2 event
2627 sameSerialization bool
28+ hasEventType bool
2729 }{
2830 {
2931 name : "same attributes and trails in same order" ,
@@ -55,6 +57,39 @@ func TestSerializeEventFromProtoConsistency(t *testing.T) {
5557 },
5658 sameSerialization : true ,
5759 },
60+ {
61+ name : "same attributes and trails in same order and event type" ,
62+ event1 : event {
63+ attributes : map [string ]any {
64+ "flour" : "500g" ,
65+ "sugar" : "250g" ,
66+ "eggs" : "2" ,
67+ "milk" : "300ml" ,
68+ "vanilla extract" : "1 tsp" ,
69+ },
70+ trails : []string {
71+ "cake" ,
72+ "viccy sponge" ,
73+ },
74+ event_type : "receipt" ,
75+ },
76+ event2 : event {
77+ attributes : map [string ]any {
78+ "flour" : "500g" ,
79+ "sugar" : "250g" ,
80+ "eggs" : "2" ,
81+ "milk" : "300ml" ,
82+ "vanilla extract" : "1 tsp" ,
83+ },
84+ trails : []string {
85+ "cake" ,
86+ "viccy sponge" ,
87+ },
88+ event_type : "receipt" ,
89+ },
90+ sameSerialization : true ,
91+ hasEventType : true ,
92+ },
5893 {
5994 name : "same attributes and trails, attributes in different order" ,
6095 event1 : event {
@@ -183,11 +218,13 @@ func TestSerializeEventFromProtoConsistency(t *testing.T) {
183218 serializableEvent1 := SerializableEvent {
184219 Attributes : test .event1 .attributes ,
185220 Trails : test .event1 .trails ,
221+ EventType : test .event1 .event_type ,
186222 }
187223
188224 serializableEvent2 := SerializableEvent {
189225 Attributes : test .event2 .attributes ,
190226 Trails : test .event2 .trails ,
227+ EventType : test .event2 .event_type ,
191228 }
192229
193230 serializedEvent1 , err := serializableEvent1 .Serialize ()
@@ -196,12 +233,24 @@ func TestSerializeEventFromProtoConsistency(t *testing.T) {
196233 serializedEvent2 , err := serializableEvent2 .Serialize ()
197234 require .Nil (t , err )
198235
236+ // check that two events serilaize to the same value
237+ // or not depending on test data
199238 if test .sameSerialization {
200239 assert .Equal (t , serializedEvent1 , serializedEvent2 )
201240 } else {
202241 assert .NotEqual (t , serializedEvent1 , serializedEvent2 )
203242 }
204243
244+ // check that event_type got serialized or ommitted if not present
245+ // in the initila data
246+ if test .hasEventType {
247+ assert .Contains (t , string (serializedEvent1 ), "event_type" )
248+ assert .Contains (t , string (serializedEvent2 ), "event_type" )
249+ } else {
250+ assert .NotContains (t , string (serializedEvent1 ), "event_type" )
251+ assert .NotContains (t , string (serializedEvent2 ), "event_type" )
252+ }
253+
205254 })
206255 }
207256}
0 commit comments