Skip to content

Commit

Permalink
Add unit tests for bootloader_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrosi committed Nov 28, 2023
1 parent 720aa38 commit 0db31fd
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 0 deletions.
Empty file added tests/unit/__init__.py
Empty file.
277 changes: 277 additions & 0 deletions tests/unit/test_bootloader_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in tests/unit/test_bootloader_settings.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

load-failure[runtimeerror]

Failed to load YAML file

# 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)

0 comments on commit 0db31fd

Please sign in to comment.