8000 chore: add conformance test coverage for typed function signature (#254) · cofin/functions-framework-python@854509a · GitHub
[go: up one dir, main page]

Skip to content

Commit 854509a

Browse files
authored
chore: add conformance test coverage for typed function signature (GoogleCloudPlatform#254)
1 parent 671f2cb commit 854509a

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

.github/workflows/conformance.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Python Conformance CI
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches:
5+
- 'master'
6+
pull_request:
37

48
# Declare default permissions as read only.
59
permissions: read-all
@@ -39,67 +43,61 @@ jobs:
3943
- name: Setup Go
4044
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
4145
with:
42-
go-version: '1.16'
46+
go-version: '1.20'
4347

4448
- name: Run HTTP conformance tests
45-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
49+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
4650
with:
47-
version: 'v1.6.0'
4851
functionType: 'http'
4952
useBuildpacks: false
5053
validateMapping: false
5154
cmd: "'functions-framework --source tests/conformance/main.py --target write_http --signature-type http'"
5255

5356
- name: Run event conformance tests
54-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
57+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
5558
with:
56-
version: 'v1.6.0'
5759
functionType: 'legacyevent'
5860
useBuildpacks: false
5961
validateMapping: true
6062
cmd: "'functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event'"
6163

6264
- name: Run CloudEvents conformance tests
63-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
65+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
6466
with:
65-
version: 'v1.6.0'
6667
functionType: 'cloudevent'
6768
useBuildpacks: false
6869
validateMapping: true
6970
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent'"
7071

7172
- name: Run HTTP conformance tests declarative
72-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
73+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
7374
with:
74-
version: 'v1.6.0'
7575
functionType: 'http'
7676
useBuildpacks: false
7777
validateMapping: false
7878
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative'"
7979

8080
- name: Run CloudEvents conformance tests declarative
81-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
81+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
8282
with:
83-
version: 'v1.6.0'
8483
functionType: 'cloudevent'
8584
useBuildpacks: false
8685
validateMapping: true
8786
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'"
8887

8988
- name: Run HTTP concurrency tests declarative
90-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
89+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
9190
with:
92-
version: 'v1.6.0'
9391
functionType: 'http'
9492
useBuildpacks: false
9593
validateConcurrency: true
9694
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'"
9795

9896
- name: Run Typed tests declarative
99-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
97+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
10098
with:
101-
version: 'v1.6.0'
10299
functionType: 'http'
100+
declarativeType: 'typed'
103101
useBuildpacks: false
104102
validateMapping: false
105-
cmd: "'functions-framework --source tests/conformance/main.py --target write_typed_event_declarative'"
103+
cmd: "'functions-framework --source tests/conformance/main.py --target typed_conformance_test'"

tests/conformance/main.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
filename = "function_output.json"
99

1010

11-
class ConformanceType:
12-
json_request: str
11+
class RawJson:
12+
data: dict
1313

14-
def __init__(self, json_request: str) -> None:
15-
self.json_request = json_request
14+
def __init__(self, data):
15+
self.data = data
1616

1717
@staticmethod
18-
def from_dict(obj: dict) -> "ConformanceType":
19-
return ConformanceType(json.dumps(obj))
18+
def from_dict(obj: dict) -> "RawJson":
19+
return RawJson(obj)
20+
21+
def to_dict(self) -> dict:
22+
return self.data
2023

2124

2225
def _write_output(content):
@@ -66,7 +69,6 @@ def write_http_declarative_concurrent(request):
6669
return "OK", 200
6770

6871

69-
@functions_framework.typed(ConformanceType)
70-
def write_typed_event_declarative(x):
71-
_write_output(x.json_request)
72-
return "OK"
72+
@functions_framework.typed(RawJson)
73+
def typed_conformance_test(x):
74+
return RawJson({"payload": x.data})

0 commit comments

Comments
 (0)
0