Skip to content
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

Fix and restructure functional tests #343

Merged
merged 17 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import os
import platform
from pathlib import Path

import pytest
from utils import RESOURCES_DIR, Resource
Expand All @@ -8,13 +10,19 @@

log = logging.getLogger(__name__)

BASES = {
"[email protected]": "focal",
"[email protected]": "jammy",
"[email protected]": "noble",
}


def pytest_addoption(parser):
parser.addoption(
"--base",
type=str.lower,
default="[email protected]",
choices=["[email protected]", "[email protected]", "[email protected]"],
choices=BASES.keys(),
help="Set base for the applications.",
)

Expand Down Expand Up @@ -100,31 +108,31 @@ def resources() -> list[Resource]:
Resource(
resource_name=TPR_RESOURCES.get(HWTool.STORCLI),
file_name="storcli.deb",
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.STORCLI)[0].replace(
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.STORCLI).replace(
"collector.", ""
),
bin_name=HWTool.STORCLI.value,
),
Resource(
resource_name=TPR_RESOURCES.get(HWTool.PERCCLI),
file_name="perccli.deb",
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.PERCCLI)[0].replace(
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.PERCCLI).replace(
"collector.", ""
),
bin_name=HWTool.PERCCLI.value,
),
Resource(
resource_name=TPR_RESOURCES.get(HWTool.SAS2IRCU),
file_name="sas2ircu",
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.SAS2IRCU)[0].replace(
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.SAS2IRCU).replace(
"collector.", ""
),
bin_name=HWTool.SAS2IRCU.value,
),
Resource(
resource_name=TPR_RESOURCES.get(HWTool.SAS3IRCU),
file_name="sas3ircu",
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.SAS3IRCU)[0].replace(
collector_name=HARDWARE_EXPORTER_COLLECTOR_MAPPING.get(HWTool.SAS3IRCU).replace(
"collector.", ""
),
bin_name=HWTool.SAS3IRCU.value,
Expand All @@ -146,3 +154,21 @@ def required_resources(resources: list[Resource], provided_collectors: set) -> l
required_resources.append(resource)

return required_resources


@pytest.fixture()
def charm_path(base: str) -> Path:
"""Fixture to determine the charm path based on the base."""
env_charm_path = f"CHARM_PATH_{BASES[base].upper()}"
rgildein marked this conversation as resolved.
Show resolved Hide resolved
path = os.getenv(env_charm_path)

if not path:
raise EnvironmentError(
f"Environment variable '{env_charm_path}' is not set for base '{base}'."
)
if not Path(path).exists():
raise FileNotFoundError(
f"The path specified in '{env_charm_path}' ({path}) does not exist."
)

return Path(path)
Loading
Loading