Skip to content

Commit

Permalink
test: working unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoppenheimer committed Oct 10, 2023
1 parent cace648 commit e67fe74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ def test_etc_hosts_entries_empty_if_not_all_units_related(harness):

def test_etc_hosts_entries_empty_if_unit_not_yet_set(harness):
with harness.hooks_disabled():
harness.set_planned_units(3)
harness.set_planned_units(2)
harness.add_relation_unit(harness.charm.peer_relation.id, f"{CHARM_KEY}/1")
harness.add_relation_unit(harness.charm.peer_relation.id, f"{CHARM_KEY}/2")
harness.update_relation_data(
harness.charm.peer_relation.id,
f"{CHARM_KEY}/0",
Expand All @@ -63,24 +62,24 @@ def test_etc_hosts_entries_empty_if_unit_not_yet_set(harness):
harness.update_relation_data(
harness.charm.peer_relation.id,
f"{CHARM_KEY}/1",
{"ip": "aragorn", "hostname": "legolas", "fqdn": "gimli"},
{"ip": "sam", "hostname": "frodo", "state": "started"},
)

assert not harness.charm.zookeeper_config.etc_hosts_entries

with harness.hooks_disabled():
harness.update_relation_data(
harness.charm.peer_relation.id, f"{CHARM_KEY}/2", {"ip": "aragorn", "fqdn": "gimli"}
harness.charm.peer_relation.id, f"{CHARM_KEY}/0", {"state": "started"}
)

assert not harness.charm.zookeeper_config.etc_hosts_entries
assert "sam" not in "".join(harness.charm.zookeeper_config.etc_hosts_entries)

with harness.hooks_disabled():
harness.update_relation_data(
harness.charm.peer_relation.id, f"{CHARM_KEY}/2", {"hostname": "legolas"}
harness.charm.peer_relation.id, f"{CHARM_KEY}/1", {"fqdn": "merry"}
)

assert harness.charm.zookeeper_config.etc_hosts_entries
assert "sam" in "".join(harness.charm.zookeeper_config.etc_hosts_entries)


def test_build_static_properties_removes_necessary_rows():
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ description = Run unit tests
commands =
poetry install --with unit
poetry run coverage run --source={[vars]src_path} \
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit/test_provider.py
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit
poetry run coverage report

[testenv:integration-{provider,password-rotation,tls,upgrade,ha,replication}]
Expand Down

0 comments on commit e67fe74

Please sign in to comment.