Skip to content

Commit bf6e20e

Browse files
authored
Use CloudEvents v1.0 in CloudEventsContext and tests (#139)
* docs: Fix link to the CloudEvents spec * fix: Use CloudEvents v1.0 in CloudEventsContext and tests CloudEvents v1.0 has renamed `schemaurl` to `dataschema` and `contenttpye` to `datacontenttype` and added subject. `CloudEventsContext` is updated with the v1.0 attributes. CloudEvents tests are also updated to use valid values. Resolves: #132, #133 * fix: Remove the dataschema attribute The current value is not the true dataschema of the payload.
1 parent 5bf1ad1 commit bf6e20e

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

src/cloudevents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CloudEventsContext } from './functions';
1919
* Checks whether the incoming request is a CloudEvents event in binary content
2020
* mode. This is verified by checking the presence of required headers.
2121
*
22-
* @link https://github.com/cloudevents/spec/blob/master/http-transport-binding.md#31-binary-content-mode
22+
* @link https://github.com/cloudevents/spec/blob/master/http-protocol-binding.md#3-http-message-mapping
2323
*
2424
* @param req Express request object.
2525
* @return True if the request is a CloudEvents event in binary content mode,

src/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export interface CloudFunctionsContext {
5757
}
5858

5959
/**
60-
* The CloudEvents v0.2 context object for the event.
60+
* The CloudEvents v1.0 context object for the event.
6161
*
62-
* @link https://github.com/cloudevents/spec/blob/v0.2/spec.md#context-attributes
62+
* @link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes
6363
*/
6464
export interface CloudEventsContext {
6565
/**

test/invoker.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -156,38 +156,47 @@ describe('CloudEvents request to event function', () => {
156156
headers: { [key: string]: string };
157157
body: {};
158158
}
159+
160+
const specversion = '1.0';
161+
const type = 'com.google.cloud.storage';
162+
const source =
163+
'https://github.com/GoogleCloudPlatform/functions-framework-nodejs';
164+
const subject = 'test-subject';
165+
const id = 'test-1234-1234';
166+
const time = '2020-05-13T01:23:45Z';
167+
const datacontenttype = 'application/json';
168+
const data = {
169+
some: 'payload',
170+
};
171+
159172
const testData: TestData[] = [
160173
{
161-
name: 'CloudEvents v0.2 structured content mode',
174+
name: 'CloudEvents v1.0 structured content mode',
162175
headers: { 'Content-Type': 'application/cloudevents+json' },
163176
body: {
164-
type: 'testType',
165-
specversion: 'testSpecversion',
166-
source: 'testSource',
167-
id: 'testId',
168-
time: 'testTime',
169-
schemaurl: 'testSchemaurl',
170-
contenttype: 'testContenttype',
171-
data: {
172-
some: 'payload',
173-
},
177+
specversion,
178+
type,
179+
source,
180+
subject,
181+
id,
182+
time,
183+
datacontenttype,
184+
data,
174185
},
175186
},
176187
{
177-
name: 'CloudEvents v0.2 binary content mode',
188+
name: 'CloudEvents v1.0 binary content mode',
178189
headers: {
179190
'Content-Type': 'application/json',
180-
'ce-type': 'testType',
181-
'ce-specversion': 'testSpecversion',
182-
'ce-source': 'testSource',
183-
'ce-id': 'testId',
184-
'ce-time': 'testTime',
185-
'ce-schemaurl': 'testSchemaurl',
186-
'ce-contenttype': 'testContenttype',
187-
},
188-
body: {
189-
some: 'payload',
191+
'ce-specversion': specversion,
192+
'ce-type': type,
193+
'ce-source': source,
194+
'ce-subject': subject,
195+
'ce-id': id,
196+
'ce-time': time,
197+
'ce-datacontenttype': datacontenttype,
190198
},
199+
body: data,
191200
},
192201
];
193202
testData.forEach(test => {
@@ -206,15 +215,15 @@ describe('CloudEvents request to event function', () => {
206215
.set(test.headers)
207216
.send(test.body)
208217
.expect(204);
209-
assert.deepStrictEqual(receivedData, { some: 'payload' });
218+
assert.deepStrictEqual(receivedData, data);
210219
assert.notStrictEqual(receivedContext, null);
211-
assert.strictEqual(receivedContext!.type, 'testType');
212-
assert.strictEqual(receivedContext!.specversion, 'testSpecversion');
213-
assert.strictEqual(receivedContext!.source, 'testSource');
214-
assert.strictEqual(receivedContext!.id, 'testId');
215-
assert.strictEqual(receivedContext!.time, 'testTime');
216-
assert.strictEqual(receivedContext!.schemaurl, 'testSchemaurl');
217-
assert.strictEqual(receivedContext!.contenttype, 'testContenttype');
220+
assert.strictEqual(receivedContext!.specversion, specversion);
221+
assert.strictEqual(receivedContext!.type, type);
222+
assert.strictEqual(receivedContext!.source, source);
223+
assert.strictEqual(receivedContext!.subject, subject);
224+
assert.strictEqual(receivedContext!.id, id);
225+
assert.strictEqual(receivedContext!.time, time);
226+
assert.strictEqual(receivedContext!.datacontenttype, datacontenttype);
218227
});
219228
});
220229
});

0 commit comments

Comments
 (0)