generated from canonical/is-charms-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17d8a37
commit 5fb6f64
Showing
4 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
# Learn more about testing at: https://juju.is/docs/sdk/testing | ||
|
||
# pylint: disable=duplicate-code,missing-function-docstring | ||
"""Unit tests.""" | ||
|
||
|
||
from pathlib import Path | ||
|
||
import ops | ||
import ops.testing | ||
import pytest | ||
from charm import K8sCharm | ||
|
||
|
||
@pytest.fixture(params=["worker", "control-plane"]) | ||
def harness(request): | ||
"""Craft a ops test harness. | ||
Args: | ||
request: pytest request object | ||
""" | ||
meta = Path(__file__).parent / "../../charmcraft.yaml" | ||
if request.param == "worker": | ||
meta = Path(__file__).parent / "../../../charmcraft.yaml" | ||
harness = ops.testing.Harness(K8sCharm, meta=meta.read_text()) | ||
harness.begin() | ||
harness.charm.is_worker = request.param == "worker" | ||
yield harness | ||
harness.cleanup() | ||
|
||
|
||
def test_configure_network_options(harness): | ||
"""Test configuring the network options. | ||
Args: | ||
harness: the harness under test | ||
""" | ||
if harness.charm.is_worker: | ||
pytest.skip("Not applicable on workers") | ||
|
||
harness.disable_hooks() | ||
|
||
harness.update_config({"network-enabled": False}) | ||
ufcg = harness.charm._assemble_cluster_config() | ||
assert not ufcg.network.enabled, "Network should be disabled" | ||
|
||
harness.update_config({"network-enabled": True}) | ||
ufcg = harness.charm._assemble_cluster_config() | ||
assert ufcg.network.enabled, "Network should be enabled" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters