8000 Add conformance tests (#95) · sesi/functions-framework-python@9c647a8 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 9c647a8

Browse files
authored
Add conformance tests (GoogleCloudPlatform#95)
* Add conformance tests * Update to version 0.3.2 of the action * Use Python-specific context properties * Updates to the test functions * Don't use buildpacks * Work around conformance test framework bug
1 parent fccb88c commit 9c647a8

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.github/workflows/conformance.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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/action@v0.3.2
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/action@v0.3.2
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/action@v0.3.2
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'"

tests/conformance/main.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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())

0 commit comments

Comments
 (0)
0