You've already forked community.general
mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-29 07:41:16 +03:00
Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9838)
Make set_module_args() a context manager, and remove copies of set_module_args(). Prepares for Data Tagging.
This commit is contained in:
@ -42,36 +42,36 @@ class TestStatsDModule(ModuleTestCase):
|
||||
"""Test udp without parameters"""
|
||||
with self.patch_udp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleFailJson) as result:
|
||||
set_module_args({})
|
||||
self.module.main()
|
||||
with set_module_args({}):
|
||||
self.module.main()
|
||||
|
||||
def test_tcp_without_parameters(self):
|
||||
"""Test tcp without parameters"""
|
||||
with self.patch_tcp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleFailJson) as result:
|
||||
set_module_args({})
|
||||
self.module.main()
|
||||
with set_module_args({}):
|
||||
self.module.main()
|
||||
|
||||
def test_udp_with_parameters(self):
|
||||
"""Test udp with parameters"""
|
||||
with self.patch_udp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'metric': 'my_counter',
|
||||
'metric_type': 'counter',
|
||||
'value': 1,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
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)
|
||||
with self.patch_udp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'metric': 'my_gauge',
|
||||
'metric_type': 'gauge',
|
||||
'value': 3,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
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)
|
||||
|
||||
@ -79,23 +79,23 @@ class TestStatsDModule(ModuleTestCase):
|
||||
"""Test tcp with parameters"""
|
||||
with self.patch_tcp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'protocol': 'tcp',
|
||||
'metric': 'my_counter',
|
||||
'metric_type': 'counter',
|
||||
'value': 1,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
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)
|
||||
with self.patch_tcp_statsd_client(side_effect=FakeStatsD) as fake_statsd:
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'protocol': 'tcp',
|
||||
'metric': 'my_gauge',
|
||||
'metric_type': 'gauge',
|
||||
'value': 3,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
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)
|
||||
|
Reference in New Issue
Block a user