diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py deleted file mode 100644 index a14942e..0000000 --- a/tests/integration/test_charm.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 -# Copyright 2023 Canonical Ltd. -# See LICENSE file for licensing details. - - -import logging -from pathlib import Path - -import pytest -import yaml - -logger = logging.getLogger(__name__) - -METADATA = yaml.safe_load(Path("./metadata.yaml").read_text()) -APP_NAME = METADATA["name"] - - -@pytest.mark.abort_on_fail -async def test_build_and_deploy(ops_test): - """Build the charm-under-test and deploy it together with related charms. - - Assert on the unit status before any relations/configurations take place. - """ - charm = await ops_test.build_charm(".") - resources = {"lego-image": METADATA["resources"]["lego-image"]["upstream-source"]} - await ops_test.model.deploy( - charm, - resources=resources, - application_name=APP_NAME, - series="jammy", - config={ - "email": "example@email.com", - "httpreq_endpoint": "http://dummy.url.com", - }, - ) - - await ops_test.model.wait_for_idle( - apps=[APP_NAME], - status="active", - raise_on_blocked=True, - timeout=1000, - ) - assert ops_test.model.applications[APP_NAME].units[0].workload_status == "active" diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py new file mode 100644 index 0000000..7554173 --- /dev/null +++ b/tests/integration/test_integration.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + + +import logging +from pathlib import Path + +import pytest +import yaml +from pytest_operator.plugin import OpsTest + +logger = logging.getLogger(__name__) + +METADATA = yaml.safe_load(Path("./metadata.yaml").read_text()) +APP_NAME = METADATA["name"] + +TLS_REQUIRER_CHARM_NAME = "tls-certificates-requirer" + + +@pytest.fixture(scope="module") +@pytest.mark.abort_on_fail +async def build_and_deploy(ops_test: OpsTest): + """Build the charm-under-test and deploy it.""" + charm = await ops_test.build_charm(".") + resources = {"lego-image": METADATA["resources"]["lego-image"]["upstream-source"]} + assert ops_test.model + await ops_test.model.deploy( + charm, + resources=resources, + application_name=APP_NAME, + series="jammy", + config={ + "email": "example@email.com", + "httpreq_endpoint": "http://dummy.url.com", + }, + ) + await ops_test.model.deploy( + TLS_REQUIRER_CHARM_NAME, + application_name=TLS_REQUIRER_CHARM_NAME, + channel="edge", + ) + + +@pytest.mark.abort_on_fail +async def test_given_charm_is_built_when_deployed_then_status_is_active( + ops_test: OpsTest, + build_and_deploy, +): + assert ops_test.model + await ops_test.model.wait_for_idle( + apps=[APP_NAME], + status="active", + timeout=1000, + ) + + +async def test_given_tls_requirer_is_deployed_and_related_then_status_is_active( + ops_test: OpsTest, + build_and_deploy, +): + assert ops_test.model + await ops_test.model.add_relation( + relation1=f"{APP_NAME}:certificates", relation2=f"{TLS_REQUIRER_CHARM_NAME}" + ) + await ops_test.model.wait_for_idle( + apps=[TLS_REQUIRER_CHARM_NAME], + status="active", + timeout=1000, + ) diff --git a/tox.ini b/tox.ini index e89f3ef..9ec6325 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ envlist = lint, static, unit src_path = {toxinidir}/src/ unit_test_path = {toxinidir}/tests/unit/ integration_test_path = {toxinidir}/tests/integration/ -all_path = {[vars]src_path} {[vars]unit_test_path} +all_path = {[vars]src_path} {[vars]unit_test_path} {[vars]integration_test_path} [testenv] setenv =