Skip to content

Commit 0497f34

Browse files
committed
Added a test for get_correlation_id() to flask implementation
1 parent 29f7403 commit 0497f34

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_flask.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def log_exception():
6363
logger.exception("Error occurred", exc_info=e)
6464
return {}
6565

66+
@app.route("/get-correlation-id")
67+
def get_correlation_id():
68+
return {'correlation_id': json_logging.get_correlation_id()}
69+
6670
with app.test_client() as test_client:
6771
yield test_client, handler
6872

@@ -121,6 +125,16 @@ def test_correlation_id_generated(client_and_log_handler):
121125
), "autogenerated UUID doesn't have expected format"
122126

123127

128+
def test_get_correlation_id(client_and_log_handler):
129+
"""Test if json_logging.get_correlation_id() finds a given correlation ID"""
130+
api_client, handler = client_and_log_handler
131+
132+
response = api_client.get("/get-correlation-id", headers={"X-Correlation-Id": "abc-def"})
133+
134+
assert response.status_code == 200
135+
assert response.json["correlation_id"] == "abc-def"
136+
137+
124138
def test_extra_property(client_and_log_handler):
125139
"""Test adding an extra property to a log message"""
126140
api_client, handler = client_and_log_handler

0 commit comments

Comments
 (0)