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
1diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
2index 31764d4..1622eb1 100644
3--- a/tests/unit/test_charm.py
4+++ b/tests/unit/test_charm.py
5@@ -7,6 +7,8 @@ import unittest
6 from base64 import b64encode
7 from copy import deepcopy
8 from mock import mock_open, patch
9+from tempfile import mkdtemp
10+from shutil import rmtree
11
12 import Config # for mockery
13 import hooks # noqa: F401; for mockery
14@@ -16,6 +18,7 @@ from hooks import (
15 add_bind_mount,
16 collect_mountpoints,
17 configure_triggers,
18+ ensure_symlink,
19 extract_ssh_public_key,
20 generate_disk_check,
21 get_managed_mounts,
22@@ -248,3 +251,30 @@ class TestUbuntuMirrorCharm(unittest.TestCase):
23 '}\n',
24 perms=0o444,
25 )
26+
27+ def test_ensure_symlink(self):
28+ try:
29+ tmpdir = mkdtemp() # Python 2 doesn't have tempfile.TemporaryDirectory
30+ target = os.path.join(tmpdir, 'target')
31+ os.mkdir(target)
32+ new_target = os.path.join(tmpdir, 'new_target')
33+ os.mkdir(new_target)
34+ link_path = os.path.join(tmpdir, 'link_path')
35+
36+ # Symlink creation works.
37+ self.assertIsNone(ensure_symlink(target, link_path))
38+ self.assertEqual(target, os.readlink(link_path))
39+
40+ # Symlink creation is idempotent.
41+ self.assertIsNone(ensure_symlink(target, link_path))
42+ self.assertEqual(target, os.readlink(link_path))
43+
44+ # Symlink replacement works.
45+ self.assertIsNone(ensure_symlink(new_target, link_path))
46+ self.assertEqual(new_target, os.readlink(link_path))
47+
48+ # Replacing a non-symlink throws an exception.
49+ with self.assertRaises(Exception):
50+ ensure_symlink(target, new_target)
51+ finally:
52+ rmtree(tmpdir)

Subscribers

People subscribed via source and target branches