Skip to content

fix unit tests #232

Description

@Abuelodelanada

Bug Description

The unit test are broken:

https://github.com/canonical/cos-proxy-operator/actions/runs/24735374187/job/72360682142?pr=230

To Reproduce

  1. tox -e unit

Environment

main branc

Relevant log output

=================================== FAILURES ===================================
_ COSProxyCharmTest.test_alert_rules_are_forwarded_on_adding_prometheus_then_targets _
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib/python3.12/unittest/case.py", line 634, in run
    self._callTestMethod(testMethod)
  File "/usr/lib/python3.12/unittest/case.py", line 589, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/usr/lib/python3.12/unittest/mock.py", line 1390, in patched
    return func(*newargs, **newkeywargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_charm.py", line 434, in test_alert_rules_are_forwarded_on_adding_prometheus_then_targets
    self.assertCountEqual(groups, GENERIC_RULES + BUNDLED_RULES + expected_groups)
  File "/usr/lib/python3.12/unittest/case.py", line 1216, in assertCountEqual
    self.fail(msg)
  File "/usr/lib/python3.12/unittest/case.py", line 715, in fail
    raise self.failureException(msg)
AssertionError: Element counts were not equal:

Diff is 3712 characters long. Set self.maxDiff to None to see it.
------------------------------ Captured log call -------------------------------
DEBUG    root:storage.py:68 Initializing SQLite local storage: :memory:.
DEBUG    cosl.cos_tool:cos_tool.py:191 Could not locate cos-tool at: "cos-tool-amd64"
DEBUG    cosl.cos_tool:cos_tool.py:62 Skipping injection of juju topology as label matchers
DEBUG    cosl.cos_tool:cos_tool.py:155 `cos-tool` unavailable. Leaving expression unchanged: vector_uptime_seconds < (vector_uptime_seconds offset 5m)
DEBUG    cosl.rules:rules.py:350 Reading rule from src/prometheus_alert_rules/vector_restarted.rule
DEBUG    cosl.cos_tool:cos_tool.py:155 `cos-tool` unavailable. Leaving expression unchanged: up < 1
DEBUG    cosl.cos_tool:cos_tool.py:155 `cos-tool` unavailable. Leaving expression unchanged: absent(up)
_ COSProxyCharmTest.test_alert_rules_are_forwarded_on_adding_targets_then_prometheus _
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib/python3.12/unittest/case.py", line 634, in run
    self._callTestMethod(testMethod)
  File "/usr/lib/python3.12/unittest/case.py", line 589, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/usr/lib/python3.12/unittest/mock.py", line 1390, in patched
    return func(*newargs, **newkeywargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_charm.py", line 485, in test_alert_rules_are_forwarded_on_adding_targets_then_prometheus
    self.assertCountEqual(groups, GENERIC_RULES + BUNDLED_RULES + expected_groups)
  File "/usr/lib/python3.12/unittest/case.py", line 1216, in assertCountEqual
    self.fail(msg)
  File "/usr/lib/python3.12/unittest/case.py", line 715, in fail
    raise self.failureException(msg)
AssertionError: Element counts were not equal:

Diff is 3712 characters long. Set self.maxDiff to None to see it.
------------------------------ Captured log call -------------------------------
DEBUG    root:storage.py:68 Initializing SQLite local storage: :memory:.
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/src/vector.py:44: SyntaxWarning: invalid escape sequence '\d'
    DEFAULT_VECTOR_CONFIG = """

tests/unit/test_charm.py: 17 warnings
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_charm.py:235: PendingDeprecationWarning: Harness is deprecated. For the recommended approach, see: https://documentation.ubuntu.com/ops/latest/howto/write-unit-tests-for-a-charm/
    self.harness = Harness(COSProxyCharm)

tests/unit/test_charm.py: 1 warning
tests/unit/test_outgoing_relation_data.py: 14 warnings
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/lib/charms/grafana_agent/v0/cos_agent.py:690: PydanticDeprecatedSince20: The `json` method is deprecated; use `model_dump_json` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.13/migration/
    relation.data[self._charm.unit][data.KEY] = data.json()

tests/unit/test_endpoint_aggregator.py: 12 warnings
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_endpoint_aggregator.py:135: PendingDeprecationWarning: Harness is deprecated. For the recommended approach, see: https://documentation.ubuntu.com/ops/latest/howto/write-unit-tests-for-a-charm/
    self.harness = Harness(EndpointAggregatorCharm, meta=AGGREGATOR_META)

tests/unit/test_endpoint_aggregator.py::TestEndpointAggregatorWithRelabeling::test_adding_prometheus_then_target_with_bad_dns_keeps_input
tests/unit/test_endpoint_aggregator.py::TestEndpointAggregatorWithRelabeling::test_adding_prometheus_then_target_with_good_dns_adds_label
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_endpoint_aggregator.py:634: PendingDeprecationWarning: Harness is deprecated. For the recommended approach, see: https://documentation.ubuntu.com/ops/latest/howto/write-unit-tests-for-a-charm/
    self.harness = Harness(EndpointResolvingAggregatorCharm, meta=AGGREGATOR_META)

tests/unit/test_outgoing_relation_data.py::TestRelationMonitors::test_cos_agent_with_downstream_prometheus
tests/unit/test_outgoing_relation_data.py::TestRelationMonitors::test_only_cos_agent
tests/unit/test_outgoing_relation_data.py::TestRelationMonitors::test_only_prometheus
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_outgoing_relation_data.py:82: PendingDeprecationWarning: Harness is deprecated. For the recommended approach, see: https://documentation.ubuntu.com/ops/latest/howto/write-unit-tests-for-a-charm/
    self.harness = Harness(COSProxyCharm)

tests/unit/test_relation_monitors.py::TestRelationMonitors::test_monitors_changed
tests/unit/test_relation_monitors.py::TestRelationMonitors::test_prometheus
  /home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit/test_relation_monitors.py:54: PendingDeprecationWarning: Harness is deprecated. For the recommended approach, see: https://documentation.ubuntu.com/ops/latest/howto/write-unit-tests-for-a-charm/
    self.harness = Harness(COSProxyCharm)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/unit/test_charm.py::COSProxyCharmTest::test_alert_rules_are_forwarded_on_adding_prometheus_then_targets - AssertionError: Element counts were not equal:
FAILED tests/unit/test_charm.py::COSProxyCharmTest::test_alert_rules_are_forwarded_on_adding_targets_then_prometheus - AssertionError: Element counts were not equal:
FAILED tests/unit/test_charm.py::COSProxyCharmTest::test_alert_rules_removal_differentiates_between_applications - AssertionError: Element counts were not equal:
FAILED tests/unit/test_charm.py::COSProxyCharmTest::test_multiple_alert_rules_are_forwarded - AssertionError: Element counts were not equal:
FAILED tests/unit/test_charm.py::COSProxyCharmTest::test_removing_alert_rules_differentiates_between_units - AssertionError: Element counts were not equal:
================== 5 failed, 40 passed, 53 warnings in 2.35s ===================
unit: exit 1 (6.31 seconds) /home/runner/work/cos-proxy-operator/cos-proxy-operator> uv run --frozen --isolated --extra=dev coverage run --source=/home/runner/work/cos-proxy-operator/cos-proxy-operator/src -m pytest /home/runner/work/cos-proxy-operator/cos-proxy-operator/tests/unit pid=3058
  unit: FAIL code 1 (7.50=setup[0.88]+cmd[0.30,6.31] seconds)
  evaluation failed :( (7.53 seconds)
Error: Process completed with exit code 1.

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions