From a4007d063f96b82545aa678ef2cb472ea3b48b1e Mon Sep 17 00:00:00 2001 From: James Baxter Date: Thu, 6 Dec 2018 18:26:32 +0000 Subject: 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. --- tests/unittests/test_handler/test_handler_write_files.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/unittests') 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) -- cgit v1.2.3