Skip to content

Commit

Permalink
Remove extra build step
Browse files Browse the repository at this point in the history
  • Loading branch information
Deezzir committed Nov 20, 2024
1 parent 992bb21 commit d90c075
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
30 changes: 28 additions & 2 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="ubuntu@22.04",
choices=["[email protected]", "[email protected]", "[email protected]"],
default="ubuntu@20.04",
choices=BASES.keys(),
help="Set base for the applications.",
)

Expand Down Expand Up @@ -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()}"
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)
10 changes: 3 additions & 7 deletions tests/functional/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,13 @@ class AppStatus(str, Enum):
@pytest.mark.abort_on_fail
@pytest.mark.skip_if_deployed
async def test_build_and_deploy( # noqa: C901, function is too complex
ops_test: OpsTest, base, architecture, provided_collectors, required_resources
ops_test: OpsTest, base, architecture, provided_collectors, required_resources, charm_path
):
"""Build the charm-under-test and deploy it together with related charms.
"""Deploy the charm together with related charms.
Assert on the unit status before any relations/configurations take place.
Optionally attach required resources when testing with real hardware.
"""
# Build and deploy charm from local source folder
charm = await ops_test.build_charm(".")
assert charm, "Charm was not built successfully."

# This is required for subordinate appliation to choose right revison
# on different architecture.
# See issue: https://bugs.launchpad.net/juju/+bug/2067749
Expand All @@ -77,7 +73,7 @@ async def test_build_and_deploy( # noqa: C901, function is too complex
logger.info("Rendering bundle %s", bundle_template_path)
bundle = ops_test.render_bundle(
bundle_template_path,
charm=charm,
charm=charm_path,
base=base,
resources={
"storcli-deb": "empty-resource",
Expand Down

0 comments on commit d90c075

Please sign in to comment.