summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJames Baxter <j.w.baxter@gmail.com>2018-12-06 18:26:32 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-12-06 18:26:32 +0000
commita4007d063f96b82545aa678ef2cb472ea3b48b1e (patch)
tree790421f5e7540b22bd646fb0f91d6274fbe51cac /tests
parenta582a2d2dff10b065b4711d583b3b158ee8b08ea (diff)
downloadvyos-cloud-init-a4007d063f96b82545aa678ef2cb472ea3b48b1e.tar.gz
vyos-cloud-init-a4007d063f96b82545aa678ef2cb472ea3b48b1e.zip
write_files: add support for appending to files.
Add 'append: true' to write_files entries to append 'content' to file specified by 'path' key. This modifies the file open mode to append.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_handler/test_handler_write_files.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_handler_write_files.py b/tests/unittests/test_handler/test_handler_write_files.py
index 7fa8fd21..bc8756ca 100644
--- a/tests/unittests/test_handler/test_handler_write_files.py
+++ b/tests/unittests/test_handler/test_handler_write_files.py
@@ -52,6 +52,18 @@ class TestWriteFiles(FilesystemMockingTestCase):
"test_simple", [{"content": expected, "path": filename}])
self.assertEqual(util.load_file(filename), expected)
+ def test_append(self):
+ self.patchUtils(self.tmp)
+ existing = "hello "
+ added = "world\n"
+ expected = existing + added
+ filename = "/tmp/append.file"
+ util.write_file(filename, existing)
+ write_files(
+ "test_append",
+ [{"content": added, "path": filename, "append": "true"}])
+ self.assertEqual(util.load_file(filename), expected)
+
def test_yaml_binary(self):
self.patchUtils(self.tmp)
data = util.load_yaml(YAML_TEXT)