Skip to content

Commit 9141673

Browse files
committed
unit tests
1 parent 30c0276 commit 9141673

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_metric.py

+26
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,32 @@ def test_lambda_metric_flush_to_log(self):
9292

9393
del os.environ["DD_FLUSH_TO_LOG"]
9494

95+
@patch("datadog_lambda.metric.logger.warning")
96+
def test_lambda_metric_invalid_metric_name_none(self, mock_logger_warning):
97+
lambda_metric(None, 1)
98+
self.mock_metric_lambda_stats.distribution.assert_not_called()
99+
mock_logger_warning.assert_called_once_with(
100+
"Ignoring metric submission. Invalid metric name: %s", None
101+
)
102+
103+
@patch("datadog_lambda.metric.logger.warning")
104+
def test_lambda_metric_invalid_metric_name_not_string(self, mock_logger_warning):
105+
lambda_metric(123, 1)
106+
self.mock_metric_lambda_stats.distribution.assert_not_called()
107+
mock_logger_warning.assert_called_once_with(
108+
"Ignoring metric submission. Invalid metric name: %s", 123
109+
)
110+
111+
@patch("datadog_lambda.metric.logger.warning")
112+
def test_lambda_metric_non_numeric_value(self, mock_logger_warning):
113+
lambda_metric("test.non_numeric", "oops")
114+
self.mock_metric_lambda_stats.distribution.assert_not_called()
115+
mock_logger_warning.assert_called_once_with(
116+
"Ignoring metric submission for metric '%s' because the value is not numeric: %r",
117+
"test.non_numeric",
118+
"oops",
119+
)
120+
95121

96122
class TestFlushThreadStats(unittest.TestCase):
97123
def setUp(self):

0 commit comments

Comments
 (0)