File tree Expand file tree Collapse file tree 2 files changed +83
-0
lines changed
Expand file tree Collapse file tree 2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Python Conformance CI
2+ on : [push, pull_request]
3+ jobs :
4+ build :
5+ runs-on : ubuntu-18.04
6+ strategy :
7+ matrix :
8+ python-version : [3.8]
9+ steps :
10+ - name : Checkout code
11+ uses : actions/checkout@v2
12+
13+ - name : Setup Python
14+ uses : actions/setup-python@v2
15+ with :
16+ python-version : ${{ matrix.python-version }}
17+
18+ - name : Install the framework
19+ run : python -m pip install -e .
20+
21+ - name : Setup Go
22+ uses : actions/setup-go@v2
23+ with :
24+ go-version : ' 1.13'
25+
26+ - name : Run HTTP conformance tests
27+ uses :
GoogleCloudPlatform/functions-framework-conformance/[email protected] 28+ with :
29+ functionType : ' http'
30+ useBuildpacks : false
31+ validateMapping : false
32+ cmd : " 'functions-framework --source tests/conformance/main.py --target write_http --signature-type http'"
33+
34+ - name : Run event conformance tests
35+ uses :
GoogleCloudPlatform/functions-framework-conformance/[email protected] 36+ with :
37+ functionType : ' legacyevent'
38+ useBuildpacks : false
39+ validateMapping : false
40+ cmd : " 'functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event'"
41+
42+ - name : Run cloudevent conformance tests
43+ uses :
GoogleCloudPlatform/functions-framework-conformance/[email protected] 44+ with :
45+ functionType : ' cloudevent'
46+ useBuildpacks : false
47+ validateMapping : false
48+ cmd : " 'functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent'"
Original file line number Diff line number Diff line change 1+ import json
2+
3+ from cloudevents .http import to_json
4+
5+ filename = "function_output.json"
6+
7+
8+ def _write_output (content ):
9+ with open (filename , "w" ) as f :
10+ f .write (content )
11+
12+
13+ def write_http (request ):
14+ _write_output (json .dumps (request .json ))
15+ return "OK" , 200
16+
17+
18+ def write_legacy_event (data , context ):
19+ _write_output (
20+ json .dumps (
21+ {
22+ "data" : data ,
23+ "context" : {
24+ "eventId" : context .event_id ,
25+ "timestamp" : context .timestamp ,
26+ "eventType" : context .event_type ,
27+ "resource" : context .resource ,
28+ },
29+ }
30+ )
31+ )
32+
33+
34+ def write_cloud_event (cloudevent ):
35+ _write_output (to_json (cloudevent ).decode ())
You can’t perform that action at this time.
0 commit comments