File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
test_functions/extension_traceparent Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -604,3 +604,13 @@ def tests_cloud_to_background_event_client_invalid_source(
604
604
resp = background_event_client .post ("/" , headers = headers , json = tempfile_payload )
605
605
606
606
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
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments