Skip to content

Commit

Permalink
Fix pull() test for latest ops that (correctly) raises path.PebbleErr…
Browse files Browse the repository at this point in the history
…or (#120)

The testing harness's pull() used to raise FileNotFoundError, but
now -- on the latest main commit -- it (correctly) raises
pebble.PathError as per the real system, so catch both.

When ops 2.1 is released this can be changed to just catch
pebble.PathError.
  • Loading branch information
benhoyt authored Jan 25, 2023
1 parent 9bd1f65 commit efd670d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ops
import yaml
from helpers import FakeProcessVersionCheck, k8s_resource_multipatch, tautology
from ops import pebble
from ops.model import ActiveStatus, BlockedStatus, Container
from ops.testing import Harness

Expand Down Expand Up @@ -122,7 +123,11 @@ def test_templates_file_not_created_if_user_provides_templates_without_config(se
templates = '{{ define "some.tmpl.variable" }}whatever it is{{ end}}'
self.harness.update_config({"templates_file": templates})

with self.assertRaises(FileNotFoundError):
# The testing harness's pull() used to raise FileNotFoundError, but
# now it (correctly) raises pebble.PathError as per the real system,
# so catch both.
# TODO: update to just pebble.PathError when ops 2.1 is released.
with self.assertRaises((pebble.PathError, FileNotFoundError)):
self.harness.charm.container.pull(self.harness.charm._templates_path)

@patch.object(AlertmanagerCharm, "_check_config", lambda *a, **kw: ("ok", ""))
Expand Down

0 comments on commit efd670d

Please sign in to comment.