Skip to content

Commit 148ad54

Browse files
committed
✅ fix(test/e2e): use direct ce msg for pubsub
Signed-off-by: Haili Zhang <haili.zhang@outlook.com>
1 parent cab1114 commit 148ad54

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

test/integration/async_server.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {deepStrictEqual, ifError, ok} from 'assert';
33
import {createServer} from 'net';
44

5-
import {get} from 'lodash';
5+
import {get, isEmpty} from 'lodash';
66
import * as shell from 'shelljs';
77
import * as MQTT from 'aedes';
88

@@ -54,7 +54,16 @@ const TEST_CONTEXT: OpenFunctionContext = {
5454
},
5555
},
5656
};
57+
5758
const TEST_PAYLOAD = {data: 'hello world'};
59+
const TEST_CLOUD_EVENT = {
60+
specversion: '1.0',
61+
id: 'test-1234-1234',
62+
type: 'ce.openfunction',
63+
source: 'https://github.com/OpenFunction/functions-framework-nodejs',
64+
traceparent: '00-65088630f09e0a5359677a7429456db7-97f23477fb2bf5ec-01',
65+
data: TEST_PAYLOAD,
66+
};
5867

5968
describe('OpenFunction - Async - Binding', () => {
6069
const APPID = 'async.dapr';
@@ -139,15 +148,12 @@ describe('OpenFunction - Async - Binding', () => {
139148

140149
it('mqtt sub w/ pub output', done => {
141150
const app = getAysncServer((ctx, data) => {
151+
if (isEmpty(data)) return;
152+
142153
// Assert that user function receives correct data from input binding
143-
try {
144-
const recieved = JSON.parse(data as string);
145-
deepStrictEqual(recieved, TEST_PAYLOAD);
146-
} catch (err) {
147-
ifError(err);
148-
}
154+
deepStrictEqual(data, TEST_PAYLOAD);
149155

150-
// Then write recived data to a local file
156+
// Then forward received data to output channel
151157
const output = 'mqtt_pub';
152158
broker.subscribe(
153159
get(TEST_CONTEXT, `outputs.${output}.uri`),
@@ -165,15 +171,17 @@ describe('OpenFunction - Async - Binding', () => {
165171

166172
// First, we start the async server
167173
app.start().then(() => {
168-
// Then, we publish a message via Dapr CLI
169-
const formatted = JSON.stringify(TEST_PAYLOAD).replace(/"/g, '\\"');
170-
shell.exec(
171-
`dapr publish -i ${APPID} -p ${
172-
TEST_CONTEXT.inputs!.mqtt_sub!.componentName
173-
} -t ${TEST_CONTEXT.inputs!.mqtt_sub.uri} -d '"${formatted}"'`,
174+
// Then, we send a cloudevent format message to server
175+
broker.publish(
174176
{
175-
silent: true,
176-
}
177+
cmd: 'publish',
178+
topic: TEST_CONTEXT.inputs!.mqtt_sub.uri!,
179+
payload: JSON.stringify(TEST_CLOUD_EVENT),
180+
qos: 0,
181+
retain: false,
182+
dup: false,
183+
},
184+
err => ifError(err)
177185
);
178186
});
179187
});

test/integration/cloud_event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {FUNCTION_STATUS_HEADER_FIELD} from '../../src/types';
2525
const TEST_CLOUD_EVENT = {
2626
specversion: '1.0',
2727
type: 'com.google.cloud.storage',
28-
source: 'https://github.com/GoogleCloudPlatform/functions-framework-nodejs',
28+
source: 'https://github.com/OpenFunction/functions-framework-nodejs',
2929
subject: 'test-subject',
3030
id: 'test-1234-1234',
3131
time: '2020-05-13T01:23:45Z',

0 commit comments

Comments
 (0)