mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-13 07:25:10 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -7,11 +7,15 @@ from __future__ import annotations
|
|||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import statsd
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
|
||||
AnsibleExitJson,
|
||||
AnsibleFailJson,
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
|
||||
|
||||
class FakeStatsD(MagicMock):
|
||||
|
||||
def incr(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
|
@ -23,7 +27,6 @@ class FakeStatsD(MagicMock):
|
|||
|
||||
|
||||
class TestStatsDModule(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
statsd.HAS_STATSD = True
|
||||
|
|
@ -33,10 +36,14 @@ class TestStatsDModule(ModuleTestCase):
|
|||
super().tearDown()
|
||||
|
||||
def patch_udp_statsd_client(self, **kwargs):
|
||||
return patch('ansible_collections.community.general.plugins.modules.statsd.udp_statsd_client', autospec=True, **kwargs)
|
||||
return patch(
|
||||
"ansible_collections.community.general.plugins.modules.statsd.udp_statsd_client", autospec=True, **kwargs
|
||||
)
|
||||
|
||||
def patch_tcp_statsd_client(self, **kwargs):
|
||||
return patch('ansible_collections.community.general.plugins.modules.statsd.tcp_statsd_client', autospec=True, **kwargs)
|
||||
return patch(
|
||||
"ansible_collections.community.general.plugins.modules.statsd.tcp_statsd_client", autospec=True, **kwargs
|
||||
)
|
||||
|
||||
def test_udp_without_parameters(self):
|
||||
"""Test udp without parameters"""
|
||||
|
|
@ -56,46 +63,54 @@ class TestStatsDModule(ModuleTestCase):
|
|||
"""Test udp with parameters"""
|
||||
with self.patch_udp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
with set_module_args({
|
||||
'metric': 'my_counter',
|
||||
'metric_type': 'counter',
|
||||
'value': 1,
|
||||
}):
|
||||
with set_module_args(
|
||||
{
|
||||
"metric": "my_counter",
|
||||
"metric_type": "counter",
|
||||
"value": 1,
|
||||
}
|
||||
):
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'Sent counter my_counter -> 1 to StatsD')
|
||||
self.assertEqual(result.exception.args[0]['changed'], True)
|
||||
self.assertEqual(result.exception.args[0]["msg"], "Sent counter my_counter -> 1 to StatsD")
|
||||
self.assertEqual(result.exception.args[0]["changed"], True)
|
||||
with self.patch_udp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
with set_module_args({
|
||||
'metric': 'my_gauge',
|
||||
'metric_type': 'gauge',
|
||||
'value': 3,
|
||||
}):
|
||||
with set_module_args(
|
||||
{
|
||||
"metric": "my_gauge",
|
||||
"metric_type": "gauge",
|
||||
"value": 3,
|
||||
}
|
||||
):
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'Sent gauge my_gauge -> 3 (delta=False) to StatsD')
|
||||
self.assertEqual(result.exception.args[0]['changed'], True)
|
||||
self.assertEqual(result.exception.args[0]["msg"], "Sent gauge my_gauge -> 3 (delta=False) to StatsD")
|
||||
self.assertEqual(result.exception.args[0]["changed"], True)
|
||||
|
||||
def test_tcp_with_parameters(self):
|
||||
"""Test tcp with parameters"""
|
||||
with self.patch_tcp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
with set_module_args({
|
||||
'protocol': 'tcp',
|
||||
'metric': 'my_counter',
|
||||
'metric_type': 'counter',
|
||||
'value': 1,
|
||||
}):
|
||||
with set_module_args(
|
||||
{
|
||||
"protocol": "tcp",
|
||||
"metric": "my_counter",
|
||||
"metric_type": "counter",
|
||||
"value": 1,
|
||||
}
|
||||
):
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'Sent counter my_counter -> 1 to StatsD')
|
||||
self.assertEqual(result.exception.args[0]['changed'], True)
|
||||
self.assertEqual(result.exception.args[0]["msg"], "Sent counter my_counter -> 1 to StatsD")
|
||||
self.assertEqual(result.exception.args[0]["changed"], True)
|
||||
with self.patch_tcp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
with set_module_args({
|
||||
'protocol': 'tcp',
|
||||
'metric': 'my_gauge',
|
||||
'metric_type': 'gauge',
|
||||
'value': 3,
|
||||
}):
|
||||
with set_module_args(
|
||||
{
|
||||
"protocol": "tcp",
|
||||
"metric": "my_gauge",
|
||||
"metric_type": "gauge",
|
||||
"value": 3,
|
||||
}
|
||||
):
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'Sent gauge my_gauge -> 3 (delta=False) to StatsD')
|
||||
self.assertEqual(result.exception.args[0]['changed'], True)
|
||||
self.assertEqual(result.exception.args[0]["msg"], "Sent gauge my_gauge -> 3 (delta=False) to StatsD")
|
||||
self.assertEqual(result.exception.args[0]["changed"], True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue