mirror of
https://git.launchpad.net/~vhaudiquet/+git/flutter-artifacts-proxy
synced 2026-02-12 01:25:53 +00:00
Initial commit
This commit is contained in:
29
tests/unit/test_charm.py
Normal file
29
tests/unit/test_charm.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Copyright 2026 Valentin Haudiquet
|
||||
# See LICENSE file for licensing details.
|
||||
#
|
||||
# To learn more about testing, see https://documentation.ubuntu.com/ops/latest/explanation/testing/
|
||||
|
||||
import pytest
|
||||
from ops import testing
|
||||
|
||||
from charm import CharmedServerCharm
|
||||
|
||||
|
||||
def mock_get_version():
|
||||
"""Get a mock version string without executing the workload code."""
|
||||
return "1.0.0"
|
||||
|
||||
|
||||
def test_start(monkeypatch: pytest.MonkeyPatch):
|
||||
"""Test that the charm has the correct state after handling the start event."""
|
||||
# Arrange:
|
||||
ctx = testing.Context(CharmedServerCharm)
|
||||
monkeypatch.setattr("charm.charmed_server.get_version", mock_get_version)
|
||||
monkeypatch.setattr("charm.charmed_server.is_installed", lambda: True)
|
||||
monkeypatch.setattr("charm.charmed_server.ensure_config", lambda: False)
|
||||
monkeypatch.setattr("charm.charmed_server.is_running", lambda: True)
|
||||
# Act:
|
||||
state_out = ctx.run(ctx.on.start(), testing.State())
|
||||
# Assert:
|
||||
assert state_out.workload_version is not None
|
||||
assert state_out.unit_status == testing.ActiveStatus()
|
||||
Reference in New Issue
Block a user