@@ -165,7 +165,97 @@ func TestMarshal(t *testing.T) {
165165 "source" : "http://example.com/source" ,
166166 },
167167 },
168- "struct data v1.0" : {
168+ "structured mode data v1.0" : {
169+ event : func () event.Event {
170+ e := event.Event {
171+ Context : event.EventContextV1 {
172+ Type : "com.example.test" ,
173+ Source : * sourceV1 ,
174+ DataSchema : schemaV1 ,
175+ ID : "ABC-123" ,
176+ Time : & now ,
177+ }.AsV1 (),
178+ }
179+ _ = e .SetData (event .ApplicationCloudEventsJSON , DataExample {
180+ AnInt : 42 ,
181+ AString : "testing" ,
182+ })
183+ return e
184+ }(),
185+ eventExtensions : map [string ]interface {}{
186+ "exbool" : true ,
187+ "exint" : int32 (42 ),
188+ "exstring" : "exstring" ,
189+ "exbinary" : []byte {0 , 1 , 2 , 3 },
190+ "exurl" : sourceV1 ,
191+ "extime" : & now ,
192+ },
193+ want : map [string ]interface {}{
194+ "specversion" : "1.0" ,
195+ "datacontenttype" : "application/cloudevents+json" ,
196+ "data" : map [string ]interface {}{
197+ "a" : 42 ,
198+ "b" : "testing" ,
199+ },
200+ "id" : "ABC-123" ,
201+ "time" : now .Format (time .RFC3339Nano ),
202+ "type" : "com.example.test" ,
203+ "exbool" : true ,
204+ "exint" : 42 ,
205+ "exstring" : "exstring" ,
206+ "exbinary" : "AAECAw==" ,
207+ "exurl" : "http://example.com/source" ,
208+ "extime" : now .Format (time .RFC3339Nano ),
209+ "dataschema" : "http://example.com/schema" ,
210+ "source" : "http://example.com/source" ,
211+ },
212+ },
213+ "structured mode batch data v1.0" : {
214+ event : func () event.Event {
215+ e := event.Event {
216+ Context : event.EventContextV1 {
217+ Type : "com.example.test" ,
218+ Source : * sourceV1 ,
219+ DataSchema : schemaV1 ,
220+ ID : "ABC-123" ,
221+ Time : & now ,
222+ }.AsV1 (),
223+ }
224+ _ = e .SetData (event .ApplicationCloudEventsBatchJSON , []DataExample {
225+ {AnInt : 42 , AString : "testing" },
226+ {AnInt : 43 , AString : "2nd testing" },
227+ })
228+ return e
229+ }(),
230+ eventExtensions : map [string ]interface {}{
231+ "exbool" : true ,
232+ "exint" : int32 (42 ),
233+ "exstring" : "exstring" ,
234+ "exbinary" : []byte {0 , 1 , 2 , 3 },
235+ "exurl" : sourceV1 ,
236+ "extime" : & now ,
237+ },
238+ want : map [string ]interface {}{
239+ "specversion" : "1.0" ,
240+ "datacontenttype" : "application/cloudevents-batch+json" ,
241+ "data" : []map [string ]interface {}{
242+ {"a" : 42 , "b" : "testing" },
243+ {"a" : 43 , "b" : "2nd testing" },
244+ },
245+ "id" : "ABC-123" ,
246+ "time" : now .Format (time .RFC3339Nano ),
247+ "type" : "com.example.test" ,
248+ "exbool" : true ,
249+ "exint" : 42 ,
250+ "exstring" : "exstring" ,
251+ "exbinary" : "AAECAw==" ,
252+ "exurl" : "http://example.com/source" ,
253+ "extime" : now .Format (time .RFC3339Nano ),
254+ "dataschema" : "http://example.com/schema" ,
255+ "source" : "http://example.com/source" ,
256+ },
257+ },
258+ "binary mode data v1.0" : {
169259 event : func () event.Event {
170260 e := event.Event {
171261 Context : event.EventContextV1 {
0 commit comments