From 365eeccbe3f6ebdba50f57ba661a1274fad00d4a Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Tue, 20 Oct 2020 14:30:26 -0500 Subject: [PATCH 1/6] Add conformance tests --- .github/workflows/conformance.yml | 48 +++++++++++++++++++++++++++++++ tests/conformance/main.py | 32 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/conformance.yml create mode 100644 tests/conformance/main.py diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml new file mode 100644 index 00000000..d9fb2f48 --- /dev/null +++ b/.github/workflows/conformance.yml @@ -0,0 +1,48 @@ +name: Python Conformance CI +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-18.04 + strategy: + matrix: + runtime: ['python38'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.13' + - name: Run HTTP conformance tests + uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.1 + with: + functionType: 'http' + validateMapping: false + source: 'tests/conformance' + target: 'write_http' + runtime: ${{ matrix.runtime }} + # TODO: Remove when tag :latest is enabled. + tag: '${{ matrix.runtime }}_20201005_20_RC00' + startDelay: 10 + - name: Run event conformance tests + uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.1 + with: + functionType: 'legacyevent' + validateMapping: false + source: 'tests/conformance' + target: 'write_legacy_event' + runtime: ${{ matrix.runtime }} + # TODO: Remove when tag :latest is enabled. + tag: '${{ matrix.runtime }}_20201005_20_RC00' + startDelay: 10 + - name: Run cloudevent conformance tests + uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.1 + with: + functionType: 'cloudevent' + validateMapping: false + source: 'tests/conformance' + target: 'write_cloud_event' + runtime: ${{ matrix.runtime }} + # TODO: Remove when tag :latest is enabled. + tag: '${{ matrix.runtime }}_20201005_20_RC00' + startDelay: 10 diff --git a/tests/conformance/main.py b/tests/conformance/main.py new file mode 100644 index 00000000..b10880f4 --- /dev/null +++ b/tests/conformance/main.py @@ -0,0 +1,32 @@ +import json + +filename = "function_output.json" + + +def _write_json(content): + with open(filename, "w") as f: + f.write(json.dumps(content)) + + +def write_http(request): + _write_json(request.json) + return "OK", 200 + + +def write_legacy_event(data, context): + _write_json( + { + "data": data, + "context": { + "eventId": context.eventId, + "timestamp": context.timestamp, + "eventType": context.eventType, + "resource": context.resource, + }, + } + ) + + +def write_cloud_event(cloudevent): + cloudevent.datacontenttype = "application/json" + _write_json(cloudevent) From 369b98bd8493e0bfde7e65ba39753ba867a05563 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Wed, 21 Oct 2020 11:57:50 -0500 Subject: [PATCH 2/6] Update to version 0.3.2 of the action --- .github/workflows/conformance.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index d9fb2f48..4cc69d18 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -14,7 +14,7 @@ jobs: with: go-version: '1.13' - name: Run HTTP conformance tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.1 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.2 with: functionType: 'http' validateMapping: false @@ -25,7 +25,7 @@ jobs: tag: '${{ matrix.runtime }}_20201005_20_RC00' startDelay: 10 - name: Run event conformance tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.1 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.2 with: functionType: 'legacyevent' validateMapping: false @@ -36,7 +36,7 @@ jobs: tag: '${{ matrix.runtime }}_20201005_20_RC00' startDelay: 10 - name: Run cloudevent conformance tests - uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.1 + uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.2 with: functionType: 'cloudevent' validateMapping: false From 3abb8d1ae164d89565d5a31f833dbb4d4b4acee7 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Wed, 21 Oct 2020 12:07:37 -0500 Subject: [PATCH 3/6] Use Python-specific context properties --- tests/conformance/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conformance/main.py b/tests/conformance/main.py index b10880f4..c3d5f59a 100644 --- a/tests/conformance/main.py +++ b/tests/conformance/main.py @@ -18,9 +18,9 @@ def write_legacy_event(data, context): { "data": data, "context": { - "eventId": context.eventId, + "eventId": context.event_id, "timestamp": context.timestamp, - "eventType": context.eventType, + "eventType": context.event_type, "resource": context.resource, }, } From 06c42eec9eb27b22dd449d1d570e3fafda7f6d79 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Wed, 21 Oct 2020 20:09:15 -0500 Subject: [PATCH 4/6] Updates to the test functions --- tests/conformance/main.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/conformance/main.py b/tests/conformance/main.py index c3d5f59a..345fccce 100644 --- a/tests/conformance/main.py +++ b/tests/conformance/main.py @@ -1,32 +1,35 @@ import json +from cloudevents.http import to_json + filename = "function_output.json" -def _write_json(content): +def _write_output(content): with open(filename, "w") as f: - f.write(json.dumps(content)) + f.write(content) def write_http(request): - _write_json(request.json) + _write_output(json.dumps(request.json)) return "OK", 200 def write_legacy_event(data, context): - _write_json( - { - "data": data, - "context": { - "eventId": context.event_id, - "timestamp": context.timestamp, - "eventType": context.event_type, - "resource": context.resource, - }, - } + _write_output( + json.dumps( + { + "data": data, + "context": { + "eventId": context.event_id, + "timestamp": context.timestamp, + "eventType": context.event_type, + "resource": context.resource, + }, + } + ) ) def write_cloud_event(cloudevent): - cloudevent.datacontenttype = "application/json" - _write_json(cloudevent) + _write_output(to_json(cloudevent).decode()) From b998711e485a95e850b86121c59be0f4a9d7585c Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Wed, 21 Oct 2020 20:25:24 -0500 Subject: [PATCH 5/6] Don't use buildpacks --- .github/workflows/conformance.yml | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 4cc69d18..2956fc1f 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -5,44 +5,44 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - runtime: ['python38'] + python-version: [3.8] steps: - name: Checkout code uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install the framework + run: python -m pip install -e . + - name: Setup Go uses: actions/setup-go@v2 with: go-version: '1.13' + - name: Run HTTP conformance tests uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.2 with: functionType: 'http' + useBuildpacks: false validateMapping: false - source: 'tests/conformance' - target: 'write_http' - runtime: ${{ matrix.runtime }} - # TODO: Remove when tag :latest is enabled. - tag: '${{ matrix.runtime }}_20201005_20_RC00' - startDelay: 10 + 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@v0.3.2 with: functionType: 'legacyevent' + useBuildpacks: false validateMapping: false - source: 'tests/conformance' - target: 'write_legacy_event' - runtime: ${{ matrix.runtime }} - # TODO: Remove when tag :latest is enabled. - tag: '${{ matrix.runtime }}_20201005_20_RC00' - startDelay: 10 + cmd: "functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event" + - name: Run cloudevent conformance tests uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.2 with: functionType: 'cloudevent' + useBuildpacks: false validateMapping: false - source: 'tests/conformance' - target: 'write_cloud_event' - runtime: ${{ matrix.runtime }} - # TODO: Remove when tag :latest is enabled. - tag: '${{ matrix.runtime }}_20201005_20_RC00' - startDelay: 10 + cmd: "functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent" From 088b54bd3dde4446a009fe69ee8042e5d5cd88c4 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Wed, 21 Oct 2020 20:32:55 -0500 Subject: [PATCH 6/6] Work around conformance test framework bug --- .github/workflows/conformance.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 2956fc1f..9be039cb 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -29,7 +29,7 @@ jobs: functionType: 'http' useBuildpacks: false validateMapping: false - cmd: "functions-framework --source tests/conformance/main.py --target write_http --signature-type http" + 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@v0.3.2 @@ -37,7 +37,7 @@ jobs: functionType: 'legacyevent' useBuildpacks: false validateMapping: false - cmd: "functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event" + cmd: "'functions-framework --source tests/conformance/main.py --target write_legacy_event --signature-type event'" - name: Run cloudevent conformance tests uses: GoogleCloudPlatform/functions-framework-conformance/action@v0.3.2 @@ -45,4 +45,4 @@ jobs: functionType: 'cloudevent' useBuildpacks: false validateMapping: false - cmd: "functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent" + cmd: "'functions-framework --source tests/conformance/main.py --target write_cloud_event --signature-type cloudevent'"