Skip to content

Commit d634996

Browse files
committed
ci: add trace test
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
1 parent b88d7aa commit d634996

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/test_functions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,13 @@ def tests_cloud_to_background_event_client_invalid_source(
604604
resp = background_event_client.post("/", headers=headers, json=tempfile_payload)
605605

606606
assert resp.status_code == 500
607+
608+
609+
def test_traceparent_header():
610+
source = TEST_FUNCTIONS_DIR / "extension_traceparent" / "main.py"
611+
target = "function"
612+
613+
client = create_app(target, source).test_client()
614+
resp = client.get("/")
615+
616+
assert resp.status_code == 200
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Function used to test handling CloudEvent functions."""
16+
import flask
17+
18+
19+
def function(cloudevent):
20+
"""Test Event function that checks to see if the CloudEvent traceparent header is populated.
21+
22+
The function returns 200 if it received the expected event, otherwise 500.
23+
24+
Args:
25+
cloudevent: A CloudEvent as defined by https://github.com/cloudevents/sdk-python.
26+
27+
Returns:
28+
HTTP status code indicating whether valid event was sent or not.
29+
"""
30+
31+
if not cloudevent["traceparent"]:
32+
flask.abort(500)

0 commit comments

Comments
 (0)