Merge ~pjdc/ubuntu-mirror-charm/+git/ubuntu-mirror-charm:test-ensure-symlink into ubuntu-mirror-charm:master

Proposed by Paul Collins
Status: Merged
Approved by: Haw Loeung
Approved revision: bea93c48017d389fb500159771d15a089b9d62b8
Merged at revision: 0a789954e76103aed38d084c46771dcc56b61c7b
Proposed branch: ~pjdc/ubuntu-mirror-charm/+git/ubuntu-mirror-charm:test-ensure-symlink
Merge into: ubuntu-mirror-charm:master
Diff against target: 52 lines (+30/-0)
1 file modified
tests/unit/test_charm.py (+30/-0)
Reviewer Review Type Date Requested Status
Haw Loeung +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+391029@code.launchpad.net

Commit message

add test_ensure_symlink

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Haw Loeung (hloeung) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 0a789954e76103aed38d084c46771dcc56b61c7b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
index 31764d4..1622eb1 100644
--- a/tests/unit/test_charm.py
+++ b/tests/unit/test_charm.py
@@ -7,6 +7,8 @@ import unittest
7from base64 import b64encode7from base64 import b64encode
8from copy import deepcopy8from copy import deepcopy
9from mock import mock_open, patch9from mock import mock_open, patch
10from tempfile import mkdtemp
11from shutil import rmtree
1012
11import Config # for mockery13import Config # for mockery
12import hooks # noqa: F401; for mockery14import hooks # noqa: F401; for mockery
@@ -16,6 +18,7 @@ from hooks import (
16 add_bind_mount,18 add_bind_mount,
17 collect_mountpoints,19 collect_mountpoints,
18 configure_triggers,20 configure_triggers,
21 ensure_symlink,
19 extract_ssh_public_key,22 extract_ssh_public_key,
20 generate_disk_check,23 generate_disk_check,
21 get_managed_mounts,24 get_managed_mounts,
@@ -248,3 +251,30 @@ class TestUbuntuMirrorCharm(unittest.TestCase):
248 '}\n',251 '}\n',
249 perms=0o444,252 perms=0o444,
250 )253 )
254
255 def test_ensure_symlink(self):
256 try:
257 tmpdir = mkdtemp() # Python 2 doesn't have tempfile.TemporaryDirectory
258 target = os.path.join(tmpdir, 'target')
259 os.mkdir(target)
260 new_target = os.path.join(tmpdir, 'new_target')
261 os.mkdir(new_target)
262 link_path = os.path.join(tmpdir, 'link_path')
263
264 # Symlink creation works.
265 self.assertIsNone(ensure_symlink(target, link_path))
266 self.assertEqual(target, os.readlink(link_path))
267
268 # Symlink creation is idempotent.
269 self.assertIsNone(ensure_symlink(target, link_path))
270 self.assertEqual(target, os.readlink(link_path))
271
272 # Symlink replacement works.
273 self.assertIsNone(ensure_symlink(new_target, link_path))
274 self.assertEqual(new_target, os.readlink(link_path))
275
276 # Replacing a non-symlink throws an exception.
277 with self.assertRaises(Exception):
278 ensure_symlink(target, new_target)
279 finally:
280 rmtree(tmpdir)

Subscribers

People subscribed via source and target branches