Skip to content

Commit d786eb5

Browse files
authored
feat: add a script to run conformance tests (#158)
1 parent 637a583 commit d786eb5

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"scripts": {
1818
"test": "mocha build/test",
19+
"test-conformance": "cd test/conformance && ./run-conformance-tests.sh",
1920
"check": "gts check",
2021
"clean": "gts clean",
2122
"compile": "tsc -p .",
@@ -31,7 +32,6 @@
3132
"bin": {
3233
"functions-framework": "./build/src/index.js",
3334
"functions-framework-nodejs": "./build/src/index.js"
34-
3535
},
3636
"author": "Google Inc.",
3737
"license": "Apache-2.0",

test/conformance/function.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const fs = require("fs");
2+
const fileName = "function_output.json";
3+
4+
function writeHttp(req, res) {
5+
writeJson(req.body);
6+
res.end(200);
7+
}
8+
9+
function writeCloudEvent(cloudevent) {
10+
cloudevent.datacontenttype = "application/json"
11+
writeJson(cloudevent);
12+
}
13+
14+
function writeLegacyEvent(data, context) {
15+
content = {
16+
data: data,
17+
context: {
18+
eventId: context.eventId,
19+
timestamp: context.timestamp,
20+
eventType: context.eventType,
21+
resource: context.resource,
22+
},
23+
};
24+
writeJson(content);
25+
}
26+
27+
function writeJson(content) {
28+
json = JSON.stringify(content);
29+
fs.writeFileSync(fileName, json);
30+
}
31+
32+
module.exports = {
33+
writeHttp,
34+
writeCloudEvent,
35+
writeLegacyEvent,
36+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Install Functions Framework for Node.js"
6+
cd ../.. && npm install && cd $OLDPWD
7+
8+
echo ""
9+
echo "Install Functions Framework Conformance"
10+
git clone https://github.com/GoogleCloudPlatform/functions-framework-conformance.git
11+
cd functions-framework-conformance/client && go build && cd $OLDPWD
12+
13+
run_test() {
14+
target=$1
15+
type=$2
16+
signature_type=${3:-"$type"}
17+
18+
echo ""
19+
echo -e "Running conformance test for $type function"
20+
./functions-framework-conformance/client/client \
21+
-cmd="node ../../build/src/index.js --target $target --signature-type $signature_type" \
22+
-type="$type" \
23+
-validate-mapping=false
24+
}
25+
26+
run_test "writeHttp" "http"
27+
run_test "writeLegacyEvent" "legacyevent" "event"
28+
run_test "writeCloudEvent" "cloudevent"
29+
30+
# Clean up.
31+
rm serverlog_stderr.txt
32+
rm serverlog_stdout.txt
33+
rm function_output.json
34+
rm -rf functions-framework-conformance

0 commit comments

Comments
 (0)