-
-
Notifications
You must be signed in to change notification settings - Fork 22
Add system and API tests #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2923da8 to
ac71c7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, after reviewing this piece of code, I performed the following refactoring:
-
Introduced a single mapping structure to reduce repetitive for-loops, improving readability and maintainability.
-
Added a helper function collect_tests to retrieve all functions starting with Test from the specified modules.
| @@ -0,0 +1,73 @@ | |||
| from inspect import getmembers, isfunction | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SUFFIX_IMG = "img" | |
| SUFFIX_ISO = "iso" | |
| tests_incusos_api_system_storage, tests_incusos_api_system_update, tests_install_external_seed, tests_install_smoke, \ | ||
| tests_install_system_checks, tests_recovery, tests_secureboot_key_rotation, tests_seed_applications, tests_seed_install, \ | ||
| tests_upgrade | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def collect_tests(modules, image, suffix=SUFFIX_IMG): | |
| """Collect only functions starting with 'Test' from given modules.""" | |
| collected = [] | |
| for mod in modules: | |
| for name, fn in getmembers(mod, isfunction): | |
| if not name.startswith("Test"): | |
| continue | |
| collected.append([f"{name}/{suffix}", fn, image]) | |
| return collected | |
| # Basic system pre-install checks | ||
| for name, fn in getmembers(tests_install_system_checks, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
|
|
||
| # Baseline install smoke tests | ||
| for name, fn in getmembers(tests_install_smoke, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| ret.append([name + "/iso", fn, image_iso]) | ||
|
|
||
| # Basic application seed tests | ||
| for name, fn in getmembers(tests_seed_applications, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
|
|
||
| # Basic install seed tests | ||
| for name, fn in getmembers(tests_seed_install, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
|
|
||
| # External install seed tests | ||
| for name, fn in getmembers(tests_install_external_seed, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
|
|
||
| # Basic system upgrade tests | ||
| for name, fn in getmembers(tests_upgrade, isfunction): | ||
| ret.append([name + "/img", fn, old_image_img]) | ||
|
|
||
| # IncusOS API tests | ||
| for name, fn in getmembers(tests_incusos_api, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_applications, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_debug, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_services, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_logging, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_network, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_provider, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_resources, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_security, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_storage, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
| for name, fn in getmembers(tests_incusos_api_system_update, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
|
|
||
| # SecureBoot key rotation tests | ||
| for name, fn in getmembers(tests_secureboot_key_rotation, isfunction): | ||
| ret.append([name + "/img", fn, image_img]) | ||
|
|
||
| # Recovery mode tests | ||
| for name, fn in getmembers(tests_recovery, isfunction): | ||
| if "_" not in name: | ||
| ret.append([name + "/img", fn, image_img]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Basic system pre-install checks | |
| for name, fn in getmembers(tests_install_system_checks, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| # Baseline install smoke tests | |
| for name, fn in getmembers(tests_install_smoke, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| ret.append([name + "/iso", fn, image_iso]) | |
| # Basic application seed tests | |
| for name, fn in getmembers(tests_seed_applications, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| # Basic install seed tests | |
| for name, fn in getmembers(tests_seed_install, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| # External install seed tests | |
| for name, fn in getmembers(tests_install_external_seed, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| # Basic system upgrade tests | |
| for name, fn in getmembers(tests_upgrade, isfunction): | |
| ret.append([name + "/img", fn, old_image_img]) | |
| # IncusOS API tests | |
| for name, fn in getmembers(tests_incusos_api, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_applications, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_debug, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_services, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_logging, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_network, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_provider, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_resources, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_security, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_storage, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| for name, fn in getmembers(tests_incusos_api_system_update, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| # SecureBoot key rotation tests | |
| for name, fn in getmembers(tests_secureboot_key_rotation, isfunction): | |
| ret.append([name + "/img", fn, image_img]) | |
| # Recovery mode tests | |
| for name, fn in getmembers(tests_recovery, isfunction): | |
| if "_" not in name: | |
| ret.append([name + "/img", fn, image_img]) | |
| # mapping table for modules and image | |
| mapping = [ | |
| # Pre-install checks | |
| ([tests_install_system_checks], image_img, SUFFIX_IMG), | |
| # Smoke tests | |
| ([tests_install_smoke], image_img, SUFFIX_IMG), | |
| ([tests_install_smoke], image_iso, SUFFIX_ISO), | |
| # Seed-related | |
| ([tests_seed_applications], image_img, SUFFIX_IMG), | |
| ([tests_seed_install], image_img, SUFFIX_IMG), | |
| ([tests_install_external_seed], image_img, SUFFIX_IMG), | |
| # Upgrade tests | |
| ([tests_upgrade], old_image_img, SUFFIX_IMG), | |
| # IncusOS API tests | |
| ( | |
| [ | |
| tests_incusos_api, | |
| tests_incusos_api_applications, | |
| tests_incusos_api_debug, | |
| tests_incusos_api_services, | |
| tests_incusos_api_system, | |
| tests_incusos_api_system_logging, | |
| tests_incusos_api_system_network, | |
| tests_incusos_api_system_provider, | |
| tests_incusos_api_system_resources, | |
| tests_incusos_api_system_security, | |
| tests_incusos_api_system_storage, | |
| tests_incusos_api_system_update, | |
| ], | |
| image_img, | |
| SUFFIX_IMG, | |
| ), | |
| # SecureBoot key rotation tests | |
| ([tests_secureboot_key_rotation], image_img, SUFFIX_IMG), | |
| # Recovery tests | |
| ([tests_recovery], image_img, SUFFIX_IMG), | |
| ] | |
| for modules, image, suffix in mapping: | |
| ret.extend(collect_tests(modules, image, suffix)) |
Signed-off-by: Mathias Gibbens <[email protected]>
ac71c7f to
96b6eb2
Compare
Closes #376