@@ -18,19 +18,22 @@ import * as sinon from 'sinon';
18
18
import { getServer } from '../../src/server' ;
19
19
import * as supertest from 'supertest' ;
20
20
21
+ // A structured CloudEvent
21
22
const TEST_CLOUD_EVENT = {
22
23
specversion : '1.0' ,
23
24
type : 'com.google.cloud.storage' ,
24
25
source : 'https://github.com/GoogleCloudPlatform/functions-framework-nodejs' ,
25
26
subject : 'test-subject' ,
26
27
id : 'test-1234-1234' ,
27
28
time : '2020-05-13T01:23:45Z' ,
28
- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
29
29
datacontenttype : 'application/json' ,
30
30
data : {
31
31
some : 'payload' ,
32
32
} ,
33
33
} ;
34
+ const TEST_EXTENSIONS = {
35
+ traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
36
+ } ;
34
37
35
38
describe ( 'CloudEvent Function' , ( ) => {
36
39
let clock : sinon . SinonFakeTimers ;
@@ -55,13 +58,10 @@ describe('CloudEvent Function', () => {
55
58
} ,
56
59
{
57
60
name : 'CloudEvents v1.0 structured content request' ,
58
- headers : {
59
- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
60
- } ,
61
+ headers : { } ,
61
62
body : TEST_CLOUD_EVENT ,
62
63
expectedCloudEvent : {
63
64
...TEST_CLOUD_EVENT ,
64
- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
65
65
} ,
66
66
} ,
67
67
{
@@ -75,9 +75,10 @@ describe('CloudEvent Function', () => {
75
75
'ce-id' : TEST_CLOUD_EVENT . id ,
76
76
'ce-time' : TEST_CLOUD_EVENT . time ,
77
77
'ce-datacontenttype' : TEST_CLOUD_EVENT . datacontenttype ,
78
- traceparent : '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01' ,
79
78
} ,
80
- body : TEST_CLOUD_EVENT . data ,
79
+ body : {
80
+ ...TEST_CLOUD_EVENT . data ,
81
+ } ,
81
82
expectedCloudEvent : TEST_CLOUD_EVENT ,
82
83
} ,
83
84
{
@@ -230,6 +231,33 @@ describe('CloudEvent Function', () => {
230
231
} ,
231
232
} ,
232
233
} ,
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
+ } ,
233
261
] ;
234
262
testData . forEach ( test => {
235
263
it ( `${ test . name } ` , async ( ) => {
0 commit comments