Skip to content

Commit

Permalink
test: Add TLS Requirer to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gruyaume committed Jan 31, 2024
1 parent fbd1617 commit fc1e294
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 44 deletions.
43 changes: 0 additions & 43 deletions tests/integration/test_charm.py

This file was deleted.

70 changes: 70 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -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,
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit fc1e294

Please sign in to comment.