Skip to content

Commit

Permalink
chore: Add conformance test for typed decorator (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
kappratiksha authored Dec 16, 2022
1 parent aa59a6b commit ccc6747
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,12 @@ jobs:
useBuildpacks: false
validateConcurrency: true
cmd: "'functions-framework --source tests/conformance/main.py --target write_http_declarative_concurrent'"

- name: Run Typed tests declarative
uses: GoogleCloudPlatform/functions-framework-conformance/action@v1.6.0
with:
version: 'v1.6.0'
functionType: 'http'
useBuildpacks: false
validateMapping: false
cmd: "'functions-framework --source tests/conformance/main.py --target write_typed_event_declarative'"
17 changes: 17 additions & 0 deletions tests/conformance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
filename = "function_output.json"


class ConformanceType:
json_request: str

def __init__(self, json_request: str) -> None:
self.json_request = json_request

@staticmethod
def from_dict(obj: dict) -> "ConformanceType":
return ConformanceType(json.dumps(obj))


def _write_output(content):
with open(filename, "w") as f:
f.write(content)
Expand Down Expand Up @@ -53,3 +64,9 @@ def write_cloud_event_declarative(cloud_event):
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"

0 comments on commit ccc6747

Please sign in to comment.