mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-03 15:51:30 -07:00
[stable-9] Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9840)
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.
(cherry picked from commit a1781d09dd
)
This commit is contained in:
parent
9a6bd80613
commit
013fb9c006
80 changed files with 3745 additions and 3977 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue