@@ -198,6 +198,94 @@ func TestUnmarshal(t *testing.T) {
198198 }),
199199 },
200200 },
201+ "structured mode data v1.0" : {
202+ body : mustJsonMarshal (t , map [string ]interface {}{
203+ "specversion" : "1.0" ,
204+ "datacontenttype" : "application/cloudevents+json" ,
205+ "data" : map [string ]interface {}{
206+ "a" : 42 ,
207+ "b" : "testing" ,
208+ },
209+ "id" : "ABC-123" ,
210+ "time" : now .Format (time .RFC3339Nano ),
211+ "type" : "com.example.test" ,
212+ "exbool" : true ,
213+ "exint" : 42 ,
214+ "exstring" : "exstring" ,
215+ "exbinary" : "AAECAw==" ,
216+ "exurl" : "http://example.com/source" ,
217+ "extime" : now .Format (time .RFC3339Nano ),
218+ "dataschema" : "http://example.com/schema" ,
219+ "source" : "http://example.com/source" ,
220+ }),
221+ want : & event.Event {
222+ Context : event.EventContextV1 {
223+ Type : "com.example.test" ,
224+ Source : * sourceV1 ,
225+ DataSchema : schemaV1 ,
226+ ID : "ABC-123" ,
227+ Time : & now ,
228+ DataContentType : event .StringOfApplicationCloudEventsJSON (),
229+ Extensions : map [string ]interface {}{
230+ "exbool" : true , // Boolean should be preserved
231+ "exint" : int32 (42 ),
232+ "exstring" : "exstring" ,
233+ // Since byte, url and time are encoded as string, the unmarshal should just convert them to string
234+ "exbinary" : "AAECAw==" ,
235+ "exurl" : "http://example.com/source" ,
236+ "extime" : now .Format (time .RFC3339Nano ),
237+ },
238+ }.AsV1 (),
239+ DataEncoded : mustJsonMarshal (t , DataExample {
240+ AnInt : 42 ,
241+ AString : "testing" ,
242+ }),
243+ },
244+ },
245+ "structured mode batch data v1.0" : {
246+ body : mustJsonMarshal (t , map [string ]interface {}{
247+ "specversion" : "1.0" ,
248+ "datacontenttype" : "application/cloudevents-batch+json" ,
249+ "data" : map [string ]interface {}{
250+ "a" : 42 ,
251+ "b" : "testing" ,
252+ },
253+ "id" : "ABC-123" ,
254+ "time" : now .Format (time .RFC3339Nano ),
255+ "type" : "com.example.test" ,
256+ "exbool" : true ,
257+ "exint" : 42 ,
258+ "exstring" : "exstring" ,
259+ "exbinary" : "AAECAw==" ,
260+ "exurl" : "http://example.com/source" ,
261+ "extime" : now .Format (time .RFC3339Nano ),
262+ "dataschema" : "http://example.com/schema" ,
263+ "source" : "http://example.com/source" ,
264+ }),
265+ want : & event.Event {
266+ Context : event.EventContextV1 {
267+ Type : "com.example.test" ,
268+ Source : * sourceV1 ,
269+ DataSchema : schemaV1 ,
270+ ID : "ABC-123" ,
271+ Time : & now ,
272+ DataContentType : event .StringOfApplicationCloudEventsBatchJSON (),
273+ Extensions : map [string ]interface {}{
274+ "exbool" : true , // Boolean should be preserved
275+ "exint" : int32 (42 ),
276+ "exstring" : "exstring" ,
277+ // Since byte, url and time are encoded as string, the unmarshal should just convert them to string
278+ "exbinary" : "AAECAw==" ,
279+ "exurl" : "http://example.com/source" ,
280+ "extime" : now .Format (time .RFC3339Nano ),
281+ },
282+ }.AsV1 (),
283+ DataEncoded : mustJsonMarshal (t , DataExample {
284+ AnInt : 42 ,
285+ AString : "testing" ,
286+ }),
287+ },
288+ },
201289 "string data v1.0" : {
202290 body : mustJsonMarshal (t , map [string ]interface {}{
203291 "specversion" : "1.0" ,
0 commit comments