Skip to content

Conversation

@gibmat
Copy link
Collaborator

@gibmat gibmat commented Oct 16, 2025

Closes #376

@gibmat gibmat force-pushed the add-system-api-tests branch 3 times, most recently from 2923da8 to ac71c7f Compare October 21, 2025 19:46
Copy link

@baconYao baconYao left a 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:

  1. Introduced a single mapping structure to reduce repetitive for-loops, improving readability and maintainability.

  2. 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +13 to +71
# 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])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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]>
@gibmat gibmat force-pushed the add-system-api-tests branch from ac71c7f to 96b6eb2 Compare October 24, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Setup API and regression testing

2 participants