Skip to content

Commit 233325e

Browse files
committed
chore: add integration tests
Signed-off-by: Dario Faccin <dario.faccin@canonical.com>
1 parent d797536 commit 233325e

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

tests/integration/test_charm.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
assert_grafana_dashboards,
1717
assert_logging,
1818
assert_metrics_endpoint,
19+
assert_security_context,
1920
deploy_and_assert_grafana_agent,
21+
generate_container_securitycontext_map,
2022
get_grafana_dashboards,
23+
get_pod_names,
2124
)
2225
from charms.kubeflow_dashboard.v0.kubeflow_dashboard_links import (
2326
DASHBOARD_LINK_LOCATIONS,
@@ -33,6 +36,7 @@
3336

3437
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
3538
CHARM_NAME = METADATA["name"]
39+
CONTAINERS_SECURITY_CONTEXT_MAP = generate_container_securitycontext_map(METADATA)
3640
CONFIG = yaml.safe_load(Path("./config.yaml").read_text())
3741
CONFIGMAP_NAME = CONFIG["options"]["dashboard-configmap"]["default"]
3842

@@ -351,7 +355,7 @@ async def test_dashboard_access(ops_test: OpsTest, lightkube_client: Client):
351355
assert "<title>Kubeflow Central Dashboard</title>" in result_text
352356

353357

354-
async def test_metrics_enpoint(ops_test):
358+
async def test_metrics_endpoint(ops_test):
355359
"""Test metrics_endpoints are defined in relation data bag and their accessibility.
356360
This function gets all the metrics_endpoints from the relation data bag, checks if
357361
they are available from the grafana-agent-k8s charm and finally compares them with the
@@ -374,3 +378,25 @@ async def test_grafana_dashboards(ops_test: OpsTest):
374378
dashboards = get_grafana_dashboards()
375379
log.info("found dashboards: %s", dashboards)
376380
await assert_grafana_dashboards(app, dashboards)
381+
382+
383+
@pytest.mark.asyncio
384+
@pytest.mark.parametrize("container_name", list(CONTAINERS_SECURITY_CONTEXT_MAP.keys()))
385+
async def test_container_security_context(
386+
ops_test: OpsTest,
387+
lightkube_client: Client,
388+
container_name: str,
389+
):
390+
"""Test container security context is correctly set.
391+
392+
Verify that container spec defines the security context with correct
393+
user ID and group ID.
394+
"""
395+
pod_name = get_pod_names(ops_test.model.name, CHARM_NAME)[0]
396+
assert_security_context(
397+
lightkube_client,
398+
pod_name,
399+
container_name,
400+
CONTAINERS_SECURITY_CONTEXT_MAP,
401+
ops_test.model.name,
402+
)

0 commit comments

Comments
 (0)