def test_handle_no_headers(self): ''' ensure that we handle events with no header key ''' event = { 'foo': 1, } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertIsNone(lr.header('X-Honeycomb-Trace'))
def test_get_header_from_headers(self): ''' Test that if headers is set, we have case-insensitive match. ''' event = { 'headers': { # case shouldn't matter 'X-HoNEyComb-TrACE': header_value, }, } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertEqual(lr.header('X-Honeycomb-Trace'), header_value)
def test_handle_sqs_none(self): ''' ensure that we handle SQS events with no honeycomb key ''' event = { "Records": [ { "body": "Hello from SQS!", "messageAttributes": {}, "eventSource": "aws:sqs", }, ], } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertIsNone(lr.header('X-Honeycomb-Trace'))
def test_handle_sns_none(self): ''' ensure that we handle SNS events with no honeycomb key ''' event = { "Records": [{ "EventSource": "aws:sns", "Sns": { "Message": "Hello from SNS!", "MessageAttributes": {} } }], } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertIsNone(lr.header('X-Honeycomb-Trace'))
def test_message_batch_is_ignored(self): ''' ensure that we don't process batches''' event = { "Records": [ { "body": "Hello from SQS!", "messageAttributes": { 'X-HoNEyComb-TrACE': { "Type": "String", "stringValue": "1;trace_id=beep,parent_id=moop,context=e29K", }, 'foo': { "Type": "String", "stringValue": "bar", }, }, "eventSource": "aws:sqs", }, { "body": "Another hello from SQS!", "messageAttributes": { 'X-HoNEyComb-TrACE': { "Type": "String", "stringValue": "1;trace_id=bloop,parent_id=scoop,context=e30K", }, 'foo': { "Type": "String", "stringValue": "baz", }, }, "eventSource": "aws:sqs", }, ], } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertIsNone(lr.header('X-Honeycomb-Trace'))
def test_handle_sns_attribute(self): ''' ensure that we extract SNS data from message attributes''' event = { "Records": [{ "EventSource": "aws:sns", "Sns": { "Message": "Hello from SNS!", "MessageAttributes": { 'X-HoNEyComb-TrACE': { "Type": "String", "Value": header_value, } } } }], } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertEqual(lr.header('X-Honeycomb-Trace'), header_value)
def test_handle_sqs_attributes(self): ''' ensure that we extract SQS data from message attributes''' event = { "Records": [ { "body": "Hello from SQS!", "messageAttributes": { 'X-HoNEyComb-TrACE': { "Type": "String", "stringValue": header_value, }, 'foo': { "Type": "String", "stringValue": "bar", }, }, "eventSource": "aws:sqs", }, ], } lr = awslambda.LambdaRequest(event) self.assertIsNotNone(lr) self.assertEqual(lr.header('X-Honeycomb-Trace'), header_value)