Skip to content

Commit

Permalink
chore: add conformance test coverage for typed function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Jun 26, 2023
1 parent f56fc1f commit 1679abe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:
- name: Setup Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version: '1.16'
go-version: '1.20'

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

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

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

- name: Run HTTP conformance tests declarative
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
with:
version: 'v1.6.0'
functionType: 'http'
Expand All @@ -78,7 +78,7 @@ jobs:
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative'"

- name: Run CloudEvents conformance tests declarative
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
with:
version: 'v1.6.0'
functionType: 'cloudevent'
Expand All @@ -87,7 +87,7 @@ jobs:
cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event_declarative'"

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

- name: Run Typed tests declarative
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
uses: GoogleCloudPlatform/functions-framework-conformance/action@5f2a796b58f099d749e70ecc83f531f6701c64af # v1.8.3
with:
version: 'v1.6.0'
functionType: 'http'
declarativeType: 'typed'
useBuildpacks: false
validateMapping: false
cmd: "'functions-framework --source tests/conformance/main.py --target write_typed_event_declarative'"
cmd: "'functions-framework --source tests/conformance/main.py --target typed_conformance_test'"
20 changes: 15 additions & 5 deletions tests/conformance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def __init__(self, json_request: str) -> None:
def from_dict(obj: dict) -> "ConformanceType":
return ConformanceType(json.dumps(obj))

class RawJson:
data: dict

def __init__(self, data):
self.data = data

@staticmethod
def from_dict(obj: dict) -> "RawJson":
return RawJson(obj)

def to_dict(self) -> dict:
return self.data

def _write_output(content):
with open(filename, "w") as f:
Expand Down Expand Up @@ -65,8 +77,6 @@ def write_http_declarative_concurrent(request):
time.sleep(1)
return "OK", 200


@functions_framework.typed(ConformanceType)
def write_typed_event_declarative(x):
_write_output(x.json_request)
return "OK"
@functions_framework.typed(RawJson)
def typed_conformance_test(x):
return RawJson({"payload": x.data})

0 comments on commit 1679abe

Please sign in to comment.