-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Prometheus scrape interface tests (#575)
* adding interface_tester base fixture * pointing to main interface tester * remove temp branch
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# # Copyright 2022 Canonical Ltd. | ||
# # See LICENSE file for licensing details. | ||
# from unittest.mock import patch | ||
|
||
from unittest.mock import patch | ||
|
||
import pytest | ||
from charm import PrometheusCharm | ||
from interface_tester import InterfaceTester | ||
from scenario import Container, ExecOutput, State | ||
|
||
|
||
def tautology(*_, **__) -> bool: | ||
return True | ||
|
||
|
||
@pytest.fixture | ||
def prometheus_charm(): | ||
with patch("lightkube.core.client.GenericSyncClient"), patch.multiple( | ||
"charm.KubernetesComputeResourcesPatch", | ||
_namespace="test-namespace", | ||
_patch=tautology, | ||
is_ready=tautology, | ||
), patch("prometheus_client.Prometheus.reload_configuration"), patch.multiple( | ||
"charm.PrometheusCharm", | ||
_promtool_check_config=lambda *_: ("stdout", ""), | ||
_prometheus_version="0.1.0", | ||
): | ||
yield PrometheusCharm | ||
|
||
|
||
def begin_with_initial_hooks_isolated() -> State: | ||
container = Container( | ||
"prometheus", | ||
can_connect=True, | ||
exec_mock={("update-ca-certificates", "--fresh"): ExecOutput(return_code=0, stdout="")}, | ||
) | ||
state = State(containers=[container], leader=True) | ||
return state | ||
|
||
|
||
@pytest.fixture | ||
def interface_tester(interface_tester: InterfaceTester, prometheus_charm): | ||
interface_tester.configure( | ||
charm_type=prometheus_charm, | ||
state_template=begin_with_initial_hooks_isolated(), | ||
) | ||
yield interface_tester |
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,11 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
from interface_tester import InterfaceTester | ||
|
||
|
||
def test_prometheus_scrape_v0_interface(interface_tester: InterfaceTester): | ||
interface_tester.configure( | ||
interface_name="prometheus_scrape", | ||
) | ||
interface_tester.run() |
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