How to test append_keys? #1341
-
I have a project with several lambdas in a state machine. I have written a function that will allow me to ensure the same keys are used as append_keys throughout each lambda so that I can have common Insight Queries and not have weird spelling or different keys between lambda logs. However, I would like to test this. I am unsure how to check if a given key has been set on the logger I would expect it to be something like this:
where in the standard_log_keys function it is taking the passed logger (possibly unneeded, but potentially useful) and simply calling how do i go about testing this is successful? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Maybe something like Although, you should really take it for-granted that if you call Assuming that def standard_log_keys(logger, **kwargs):
allowed_keys = {"a", "b", "c"}
for k in kwargs:
if k not in allowed_keys:
raise ValueError(f"'{k}' is not an allowed log key")
logger.append_keys(**kwargs) I'd have a test to ensure that passing an unexpected key causes the validation error to raise, and a test that ensures |
Beta Was this translation helpful? Give feedback.
-
I agree - not trying to test the logger itself, but rather a reusable function that adds the same keys to multiple lambda I'll try out what you provided! Testing it from thst angle makes a lot of sense and perhaps it will be easier. Thanks for the possibility |
Beta Was this translation helpful? Give feedback.
Maybe something like
logger.registered_formatter.log_format.get("quote_id") == "Test"
?Although, you should really take it for-granted that if you call
logger.append_keys(quote_id=value_passed)
that"quote_id"
will be in your logs with the correct value. If there was an error in that component of the library, it would be found out pretty quickly by the community of users and addressed.Assuming that
standard_log_keys()
is something like this:I'd have a test to en…