Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Apr 28, 2023
1 parent a9aa410 commit 51c1c17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def _on_config_changed(self, event: ConfigChangedEvent) -> None:
self._handle_status_update_config(event)

def _cleanup(self, event: RemoveEvent) -> None:
logger.info("Removing charm")
self.network_policy_handler.delete_ingress_policies()

def _update_kratos_endpoints_relation_data(self, event: RelationEvent) -> None:
Expand Down
42 changes: 25 additions & 17 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,26 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
Assert on the unit status before any relations/configurations take place.
"""
await ops_test.model.deploy(
POSTGRES,
channel="14/stable",
trust=True,
)
charm = await ops_test.build_charm(".")
resources = {"oci-image": METADATA["resources"]["oci-image"]["upstream-source"]}
await ops_test.model.deploy(
charm, resources=resources, application_name=APP_NAME, trust=True, series="jammy"
)
await ops_test.model.add_relation(APP_NAME, POSTGRES)

async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[APP_NAME, POSTGRES],
status="active",
raise_on_blocked=True,
timeout=1000,
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "active"


async def test_ingress_relation(ops_test: OpsTest, client: Client) -> None:
Expand Down Expand Up @@ -88,23 +103,6 @@ async def test_ingress_relation(ops_test: OpsTest, client: Client) -> None:
assert policy


async def test_postgres_relation(ops_test: OpsTest) -> None:
await ops_test.model.deploy(
POSTGRES,
channel="14/stable",
trust=True,
)
await ops_test.model.add_relation(APP_NAME, POSTGRES)

async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[APP_NAME, POSTGRES],
status="active",
timeout=1000,
)
assert ops_test.model.applications[APP_NAME].units[0].workload_status == "active"


async def test_has_public_ingress(ops_test: OpsTest) -> None:
# Get the traefik address and try to reach kratos
public_address = await get_unit_address(ops_test, TRAEFIK_PUBLIC_APP, 0)
Expand Down Expand Up @@ -263,3 +261,13 @@ async def test_identity_schemas_config(ops_test: OpsTest) -> None:
resp = requests.get(f"http://{public_address}/{ops_test.model.name}-{APP_NAME}/schemas")

assert original_resp == resp.json()

@pytest.mark.skip(
reason=("sometimes the event hook is not fired so the resources don't get cleaned up.")
)
async def test_charm_removal(ops_test: OpsTest, client: Client) -> None:
await ops_test.model.remove_application(APP_NAME, force=True, block_until_done=True, destroy_storage=True)

# Validate network policies are removed when ingress is provided
policy = client.get(NetworkPolicy, "kratos-network-policy", namespace=ops_test.model.name)
assert not policy

0 comments on commit 51c1c17

Please sign in to comment.