@@ -18,19 +18,22 @@ import * as sinon from 'sinon';
1818import { getServer } from '../../src/server' ;
1919import * as supertest from 'supertest' ;
2020
21+ // A structured CloudEvent
2122const TEST_CLOUD_EVENT = {
2223 specversion : '1.0' ,
2324 type : 'com.google.cloud.storage' ,
2425 source : 'https://github.com/GoogleCloudPlatform/functions-framework-nodejs' ,
2526 subject : 'test-subject' ,
2627 id : 'test-1234-1234' ,
2728 time : '2020-05-13T01:23:45Z' ,
28- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
2929 datacontenttype : 'application/json' ,
3030 data : {
3131 some : 'payload' ,
3232 } ,
3333} ;
34+ const TEST_EXTENSIONS = {
35+ traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
36+ } ;
3437
3538describe ( 'CloudEvent Function' , ( ) => {
3639 let clock : sinon . SinonFakeTimers ;
@@ -55,13 +58,10 @@ describe('CloudEvent Function', () => {
5558 } ,
5659 {
5760 name : 'CloudEvents v1.0 structured content request' ,
58- headers : {
59- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
60- } ,
61+ headers : { } ,
6162 body : TEST_CLOUD_EVENT ,
6263 expectedCloudEvent : {
6364 ...TEST_CLOUD_EVENT ,
64- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
6565 } ,
6666 } ,
6767 {
@@ -75,9 +75,10 @@ describe('CloudEvent Function', () => {
7575 'ce-id' : TEST_CLOUD_EVENT . id ,
7676 'ce-time' : TEST_CLOUD_EVENT . time ,
7777 'ce-datacontenttype' : TEST_CLOUD_EVENT . datacontenttype ,
78- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
7978 } ,
80- body : TEST_CLOUD_EVENT . data ,
79+ body : {
80+ ...TEST_CLOUD_EVENT . data ,
81+ } ,
8182 expectedCloudEvent : TEST_CLOUD_EVENT ,
8283 } ,
8384 {
@@ -230,6 +231,33 @@ describe('CloudEvent Function', () => {
230231 } ,
231232 } ,
232233 } ,
234+ {
235+ name : 'CloudEvents v1.0 traceparent extension – structured' ,
236+ headers : {
237+ 'Content-Type' : 'application/cloudevents+json' ,
238+ ...TEST_EXTENSIONS ,
239+ } ,
240+ body : TEST_CLOUD_EVENT ,
241+ expectedCloudEvent : { ...TEST_CLOUD_EVENT , ...TEST_EXTENSIONS } ,
242+ } ,
243+ {
244+ name : 'CloudEvents v1.0 traceparent extension – binary' ,
245+ headers : {
246+ 'Content-Type' : 'application/json' ,
247+ 'ce-specversion' : TEST_CLOUD_EVENT . specversion ,
248+ 'ce-type' : TEST_CLOUD_EVENT . type ,
249+ 'ce-source' : TEST_CLOUD_EVENT . source ,
250+ 'ce-subject' : TEST_CLOUD_EVENT . subject ,
251+ 'ce-id' : TEST_CLOUD_EVENT . id ,
252+ 'ce-time' : TEST_CLOUD_EVENT . time ,
253+ 'ce-datacontenttype' : TEST_CLOUD_EVENT . datacontenttype ,
254+ ...TEST_EXTENSIONS ,
255+ } ,
256+ body : {
257+ ...TEST_CLOUD_EVENT . data ,
258+ } ,
259+ expectedCloudEvent : { ...TEST_CLOUD_EVENT , ...TEST_EXTENSIONS } ,
260+ } ,
233261 ] ;
234262 testData . forEach ( test => {
235263 it ( `${ test . name } ` , async ( ) => {
0 commit comments