File tree Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Expand file tree Collapse file tree 3 files changed +71
-1
lines changed Original file line number Diff line number Diff line change 16
16
},
17
17
"scripts" : {
18
18
"test" : " mocha build/test" ,
19
+ "test-conformance" : " cd test/conformance && ./run-conformance-tests.sh" ,
19
20
"check" : " gts check" ,
20
21
"clean" : " gts clean" ,
21
22
"compile" : " tsc -p ." ,
31
32
"bin" : {
32
33
"functions-framework" : " ./build/src/index.js" ,
33
34
"functions-framework-nodejs" : " ./build/src/index.js"
34
-
35
35
},
36
36
"author" : " Google Inc." ,
37
37
"license" : " Apache-2.0" ,
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments