New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve API compatibility for next release #292
Changes from 11 commits
69a910b
f9c3664
6c85be4
4879e38
09a7d6e
4f8f3b7
b97fc28
f213076
16bd629
a526c8b
fb54301
001b3be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,23 @@ def test_format_minimal(self): | |
value, result[key], f"expected_payload[{key}] != result[{key}]" | ||
) | ||
|
||
def test_format_with_quotes(self): | ||
""" | ||
When logging a message containing quotes, escape chars should be added | ||
""" | ||
import logging | ||
import json | ||
|
||
handler = self._make_one() | ||
message = '"test"' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are other special chars escaped as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen any that need it. Let me know if you find others, I imagine it will be the same across languages |
||
expected_result = '\\"test\\"' | ||
record = logging.LogRecord(None, logging.INFO, None, None, message, None, None,) | ||
record.created = None | ||
handler.filter(record) | ||
result = json.loads(handler.format(record)) | ||
result["message"] = expected_result | ||
self.assertEqual(result["message"], expected_result) | ||
|
||
def test_format_with_request(self): | ||
import logging | ||
import json | ||
|
@@ -121,23 +138,21 @@ def test_format_with_request(self): | |
"logging.googleapis.com/trace": expected_trace, | ||
"logging.googleapis.com/spanId": expected_span, | ||
"httpRequest": { | ||
"requestMethod": "PUT", | ||
"requestMethod": "GET", | ||
"requestUrl": expected_path, | ||
"userAgent": expected_agent, | ||
"protocol": "HTTP/1.1", | ||
}, | ||
} | ||
|
||
app = self.create_app() | ||
with app.test_client() as c: | ||
c.put( | ||
path=expected_path, | ||
data="body", | ||
headers={ | ||
"User-Agent": expected_agent, | ||
"X_CLOUD_TRACE_CONTEXT": trace_header, | ||
}, | ||
) | ||
with app.test_request_context( | ||
expected_path, | ||
headers={ | ||
"User-Agent": expected_agent, | ||
"X_CLOUD_TRACE_CONTEXT": trace_header, | ||
}, | ||
): | ||
handler.filter(record) | ||
result = json.loads(handler.format(record)) | ||
for (key, value) in expected_payload.items(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great commenting throughout this PR.