forked from DataDog/datadog-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tags.py
More file actions
74 lines (63 loc) · 2.49 KB
/
test_tags.py
File metadata and controls
74 lines (63 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import unittest
try:
from unittest.mock import patch, MagicMock
except ImportError:
from mock import patch, MagicMock
from datadog_lambda.tags import parse_lambda_tags_from_arn, get_runtime_tag
def get_mock_context(
invoked_function_arn="arn:aws:lambda:us-east-1:1234597598159:function:swf-hello-test:$Latest",
function_version="1",
):
lambda_context = MagicMock()
lambda_context.invoked_function_arn = invoked_function_arn
lambda_context.function_version = function_version
return lambda_context
class TestMetricTags(unittest.TestCase):
def setUp(self):
patcher = patch("datadog_lambda.tags.python_version_tuple")
self.mock_python_version_tuple = patcher.start()
self.addCleanup(patcher.stop)
def test_parse_lambda_tags_from_arn_latest(self):
self.assertListEqual(
parse_lambda_tags_from_arn(get_mock_context()),
[
"region:us-east-1",
"account_id:1234597598159",
"functionname:swf-hello-test",
"resource:swf-hello-test:Latest",
],
)
def test_parse_lambda_tags_from_arn_version(self):
lambda_context = get_mock_context()
lambda_context.invoked_function_arn = (
"arn:aws:lambda:us-east-1:1234597598159:function:swf-hello-test:3"
)
self.assertListEqual(
parse_lambda_tags_from_arn(lambda_context),
[
"region:us-east-1",
"account_id:1234597598159",
"functionname:swf-hello-test",
"resource:swf-hello-test:3",
],
)
def test_parse_lambda_tags_from_arn_alias(self):
lambda_context = get_mock_context()
lambda_context.invoked_function_arn = (
"arn:aws:lambda:us-east-1:1234597598159:function:swf-hello-test:my_alias-1"
)
self.assertListEqual(
parse_lambda_tags_from_arn(lambda_context),
[
"region:us-east-1",
"account_id:1234597598159",
"functionname:swf-hello-test",
"executedversion:1",
"resource:swf-hello-test:my_alias-1",
],
)
def test_get_runtime_tag(self):
self.mock_python_version_tuple.return_value = ("2", "7", "10")
self.assertEqual(get_runtime_tag(), "runtime:python2.7")
self.mock_python_version_tuple.return_value = ("3", "7", "2")
self.assertEqual(get_runtime_tag(), "runtime:python3.7")