Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryxias committed Apr 6, 2020
1 parent 28e4f69 commit f3f1426
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions conf/outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"aws-lambda": {
"sample-lambda": "function-name:qualifier"
},
"aws-lambda-v2": [
"sample-lambda"
],
"aws-s3": {
"bucket": "aws-s3-bucket"
},
Expand Down
41 changes: 40 additions & 1 deletion tests/unit/streamalert/alert_processor/outputs/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
SESOutput,
SNSOutput,
SQSOutput,
CloudwatchLogOutput
CloudwatchLogOutput,
LambdaOutputV2,
)
from tests.unit.streamalert.alert_processor import (
CONFIG,
Expand Down Expand Up @@ -151,6 +152,44 @@ def test_dispatch_with_qualifier(self, log_mock):
self.SERVICE, alt_descriptor)


@patch.object(aws_outputs, 'boto3', MagicMock())
class TestLambdaV2Output:
"""Test class for LambdaOutput"""
DESCRIPTOR = 'unit_test_lambda'
SERVICE = 'aws-lambda-v2'
OUTPUT = ':'.join([SERVICE, DESCRIPTOR])
CREDS = {
'lambda_function_arn': 'arn:aws:lambda:us-east-1:11111111:function:my_func',
'function_qualifier': 'production',
'assume_role_arn': 'arn:aws:iam::11111111:role/my_path/my_role',
}

@patch('streamalert.alert_processor.outputs.output_base.OutputCredentialsProvider')
def setup(self, provider_constructor):
"""Setup before each method"""
provider = MagicMock()
provider_constructor.return_value = provider
provider.load_credentials = Mock(
side_effect=lambda x: self.CREDS if x == self.DESCRIPTOR else None
)

self._provider = provider
self._dispatcher = LambdaOutputV2(None)

def test_locals(self):
"""LambdaOutput local variables"""
assert_equal(self._dispatcher.__class__.__name__, 'LambdaOutputV2')
assert_equal(self._dispatcher.__service__, self.SERVICE)

@patch('logging.Logger.info')
def test_dispatch(self, log_mock):
"""LambdaOutput dispatch"""
assert_true(self._dispatcher.dispatch(get_alert(), self.OUTPUT))

log_mock.assert_called_with('Successfully sent alert to %s:%s',
self.SERVICE, self.DESCRIPTOR)


@mock_s3
class TestS3Output:
"""Test class for S3Output"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_output_loading():
expected_outputs = {
'aws-firehose',
'aws-lambda',
'aws-lambda-v2',
'aws-s3',
'aws-ses',
'aws-sns',
Expand Down

0 comments on commit f3f1426

Please sign in to comment.