generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for bootloader_settings
- Loading branch information
Showing
2 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (c) 2023, Sergei Petrosian <[email protected]> | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
# | ||
""" Unit tests for the bootloader_settings module """ | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
__metaclass__ = type | ||
|
||
from unittest import TestCase, mock | ||
|
||
# import os | ||
# import tempfile | ||
# import shutil | ||
# import unittest | ||
# import re | ||
# import copy | ||
# from configobj import ConfigObj | ||
|
||
# try: | ||
# from unittest.mock import Mock | ||
# except ImportError: | ||
# from mock import Mock | ||
|
||
# import kernel_settings | ||
# import tuned | ||
|
||
bootloader_settings: [ | ||
{ | ||
"kernel": { | ||
"kernel_index": [ | ||
0, | ||
1 | ||
] | ||
}, | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": { | ||
"kernel_index": 2 | ||
}, | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": { | ||
"kernel_path": [ | ||
"/path/1", | ||
"/path/2" | ||
] | ||
}, | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": { | ||
"kernel_path": "/path/3" | ||
}, | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": { | ||
"kernel_title": [ | ||
"Fedora Linux (1.1.11-100.fc37.x86_64) 37 (Workstation Edition)", | ||
"Fedora Linux (2.2.22-200.fc37.x86_64) 37 (Workstation Edition)" | ||
] | ||
}, | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": { | ||
"kernel_title": "Fedora Linux (3.3.33-300.fc37.x86_64) 37 (Workstation Edition)" | ||
}, | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": "DEFAULT", | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
}, | ||
{ | ||
"kernel": "ALL", | ||
"options": [ | ||
{ | ||
"name": "arg_with_str_value", | ||
"value": "test_value" | ||
}, | ||
{ | ||
"name": "arg_with_int_value", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "arg_with_state_present", | ||
"state": "present" | ||
}, | ||
{ | ||
"name": "arg_without_state_present" | ||
}, | ||
{ | ||
"name": "arg_without_state_absent", | ||
"state": "absent" | ||
}, | ||
{ | ||
"previous": "replaced" | ||
} | ||
] | ||
} | ||
] | ||
|
||
|
||
class InputValidator(TestCase): | ||
"""test functions that process bootloader_settings argument""" | ||
|
||
def test_get_kernels(self): | ||
"""test get_kernels function against sample input""" | ||
kernels = get_kernels(bootloader_settings[0]["kernel"]) | ||
self.assertEqual([0, 1], kernels) |