Skip to content

Commit

Permalink
Cover additional paths when running snap commands
Browse files Browse the repository at this point in the history
  • Loading branch information
james-garner-canonical committed Sep 6, 2024
1 parent b2befeb commit ec806bd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/unit/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,18 +713,27 @@ def setUp(self, mock_exists, m):
snap._Cache.cache._load_available_snaps()

@patch("charms.operator_libs_linux.v2.snap.subprocess.check_output")
def test_can_run_bare_changes(self, mock_subprocess):
def test_can_run_bare_changes(self, mock_subprocess: MagicMock):
mock_subprocess.return_value = 0
foo = snap.add("curl", classic=True, channel="latest")
mock_subprocess.assert_called_with(
["snap", "install", "curl", "--classic", '--channel="latest"'],
universal_newlines=True,
)
self.assertTrue(foo.present)
snap.add("curl", state="latest") # cover string conversion path
mock_subprocess.assert_called_with(
["snap", "refresh", "curl", '--channel="latest"'],
universal_newlines=True,
)
with self.assertRaises(TypeError): # cover error path
snap.add(snap_names=[])

bar = snap.remove("curl")
mock_subprocess.assert_called_with(["snap", "remove", "curl"], universal_newlines=True)
self.assertFalse(bar.present)
with self.assertRaises(TypeError): # cover error path
snap.remove(snap_names=[])

baz = snap.add("curl", classic=True, revision=123)
mock_subprocess.assert_called_with(
Expand Down

0 comments on commit ec806bd

Please sign in to comment.