mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-23 04:09:04 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -6,11 +6,15 @@ from __future__ import annotations
|
|||
|
||||
from unittest.mock import patch
|
||||
from ansible_collections.community.general.plugins.modules import bootc_manage
|
||||
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 TestBootcManageModule(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.module = bootc_manage
|
||||
|
|
@ -20,52 +24,52 @@ class TestBootcManageModule(ModuleTestCase):
|
|||
|
||||
def test_switch_without_image(self):
|
||||
"""Failure if state is 'switch' but no image provided"""
|
||||
with set_module_args({'state': 'switch'}):
|
||||
with set_module_args({"state": "switch"}):
|
||||
with self.assertRaises(AnsibleFailJson) as result:
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], "state is switch but all of the following are missing: image")
|
||||
self.assertEqual(result.exception.args[0]["msg"], "state is switch but all of the following are missing: image")
|
||||
|
||||
def test_switch_with_image(self):
|
||||
"""Test successful switch with image provided"""
|
||||
with set_module_args({'state': 'switch', 'image': 'example.com/image:latest'}):
|
||||
with patch('ansible.module_utils.basic.AnsibleModule.run_command') as run_command_mock:
|
||||
run_command_mock.return_value = (0, 'Queued for next boot: ', '')
|
||||
with set_module_args({"state": "switch", "image": "example.com/image:latest"}):
|
||||
with patch("ansible.module_utils.basic.AnsibleModule.run_command") as run_command_mock:
|
||||
run_command_mock.return_value = (0, "Queued for next boot: ", "")
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
self.module.main()
|
||||
self.assertTrue(result.exception.args[0]['changed'])
|
||||
self.assertTrue(result.exception.args[0]["changed"])
|
||||
|
||||
def test_latest_state(self):
|
||||
"""Test successful upgrade to the latest state"""
|
||||
with set_module_args({'state': 'latest'}):
|
||||
with patch('ansible.module_utils.basic.AnsibleModule.run_command') as run_command_mock:
|
||||
run_command_mock.return_value = (0, 'Queued for next boot: ', '')
|
||||
with set_module_args({"state": "latest"}):
|
||||
with patch("ansible.module_utils.basic.AnsibleModule.run_command") as run_command_mock:
|
||||
run_command_mock.return_value = (0, "Queued for next boot: ", "")
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
self.module.main()
|
||||
self.assertTrue(result.exception.args[0]['changed'])
|
||||
self.assertTrue(result.exception.args[0]["changed"])
|
||||
|
||||
def test_latest_state_no_change(self):
|
||||
"""Test no change for latest state"""
|
||||
with set_module_args({'state': 'latest'}):
|
||||
with patch('ansible.module_utils.basic.AnsibleModule.run_command') as run_command_mock:
|
||||
run_command_mock.return_value = (0, 'No changes in ', '')
|
||||
with set_module_args({"state": "latest"}):
|
||||
with patch("ansible.module_utils.basic.AnsibleModule.run_command") as run_command_mock:
|
||||
run_command_mock.return_value = (0, "No changes in ", "")
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
self.module.main()
|
||||
self.assertFalse(result.exception.args[0]['changed'])
|
||||
self.assertFalse(result.exception.args[0]["changed"])
|
||||
|
||||
def test_switch_image_failure(self):
|
||||
"""Test failure during image switch"""
|
||||
with set_module_args({'state': 'switch', 'image': 'example.com/image:latest'}):
|
||||
with patch('ansible.module_utils.basic.AnsibleModule.run_command') as run_command_mock:
|
||||
run_command_mock.return_value = (1, '', 'ERROR')
|
||||
with set_module_args({"state": "switch", "image": "example.com/image:latest"}):
|
||||
with patch("ansible.module_utils.basic.AnsibleModule.run_command") as run_command_mock:
|
||||
run_command_mock.return_value = (1, "", "ERROR")
|
||||
with self.assertRaises(AnsibleFailJson) as result:
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'ERROR: Command execution failed.')
|
||||
self.assertEqual(result.exception.args[0]["msg"], "ERROR: Command execution failed.")
|
||||
|
||||
def test_latest_state_failure(self):
|
||||
"""Test failure during upgrade"""
|
||||
with set_module_args({'state': 'latest'}):
|
||||
with patch('ansible.module_utils.basic.AnsibleModule.run_command') as run_command_mock:
|
||||
run_command_mock.return_value = (1, '', 'ERROR')
|
||||
with set_module_args({"state": "latest"}):
|
||||
with patch("ansible.module_utils.basic.AnsibleModule.run_command") as run_command_mock:
|
||||
run_command_mock.return_value = (1, "", "ERROR")
|
||||
with self.assertRaises(AnsibleFailJson) as result:
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'ERROR: Command execution failed.')
|
||||
self.assertEqual(result.exception.args[0]["msg"], "ERROR: Command execution failed.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue