Skip to content

Commit 1679abe

Browse files
committed
chore: add conformance test coverage for typed function signature
1 parent f56fc1f commit 1679abe

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

.github/workflows/conformance.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ jobs:
3939
- name: Setup Go
4040
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
4141
with:
42-
go-version: '1.16'
42+
go-version: '1.20'
4343

4444
- name: Run HTTP conformance tests
45-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
45+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
4646
with:
4747
version: 'v1.6.0'
4848
functionType: 'http'
@@ -51,7 +51,7 @@ jobs:
5151
cmd: "'functions-framework --source tests/conformance/main.py --target write_http --signature-type http'"
5252

5353
- name: Run event conformance tests
54-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
54+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
5555
with:
5656
version: 'v1.6.0'
5757
functionType: 'legacyevent'
@@ -60,7 +60,7 @@ jobs:
6060
cmd: "'functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event'"
6161

6262
- name: Run CloudEvents conformance tests
63-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
63+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
6464
with:
6565
version: 'v1.6.0'
6666
functionType: 'cloudevent'
@@ -69,7 +69,7 @@ jobs:
6969
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent'"
7070

7171
- name: Run HTTP conformance tests declarative
72-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
72+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
7373
with:
7474
version: 'v1.6.0'
7575
functionType: 'http'
@@ -78,7 +78,7 @@ jobs:
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:
8383
version: 'v1.6.0'
8484
functionType: 'cloudevent'
@@ -87,7 +87,7 @@ jobs:
8787
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'"
8888

8989
- name: Run HTTP concurrency tests declarative
90-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
90+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
9191
with:
9292
version: 'v1.6.0'
9393
functionType: 'http'
@@ -96,10 +96,11 @@ jobs:
9696
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'"
9797

9898
- name: Run Typed tests declarative
99-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
99+
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
100100
with:
101101
version: 'v1.6.0'
102102
functionType: 'http'
103+
declarativeType: 'typed'
103104
useBuildpacks: false
104105
validateMapping: false
105-
cmd: "'functions-framework --source tests/conformance/main.py --target write_typed_event_declarative'"
106+
cmd: "'functions-framework --source tests/conformance/main.py --target typed_conformance_test'"

tests/conformance/main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ def __init__(self, json_request: str) -> None:
1818
def from_dict(obj: dict) -> "ConformanceType":
1919
return ConformanceType(json.dumps(obj))
2020

21+
class RawJson:
22+
data: dict
23+
24+
def __init__(self, data):
25+
self.data = data
26+
27+
@staticmethod
28+
def from_dict(obj: dict) -> "RawJson":
29+
return RawJson(obj)
30+
31+
def to_dict(self) -> dict:
32+
return self.data
2133

2234
def _write_output(content):
2335
with open(filename, "w") as f:
@@ -65,8 +77,6 @@ def write_http_declarative_concurrent(request):
6577
time.sleep(1)
6678
return "OK", 200
6779

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

0 commit comments

Comments
 (0)