summaryrefslogtreecommitdiff
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authorBen Howard <ben.howard@ubuntu.com>2015-07-02 15:14:26 -0600
committerusd-importer <ubuntu-server@lists.ubuntu.com>2015-07-03 16:03:20 +0000
commite329a411ba4b518e899251b0b28b6f00f066ab16 (patch)
tree8f824487afd717fca96bbec3fd1f4c63320ba916 /tests/test_utils.py
parent873472a8013d1d77298c347507c51be1ee1b2375 (diff)
parent4d3f2d83da5663fd03d7ace3c4c5054bdac13151 (diff)
downloadvyos-walinuxagent-e329a411ba4b518e899251b0b28b6f00f066ab16.tar.gz
vyos-walinuxagent-e329a411ba4b518e899251b0b28b6f00f066ab16.zip
Import patches-applied version 2.0.13-0ubuntu1 to applied/ubuntu/wily-proposed
Imported using git-ubuntu import. Changelog parent: 873472a8013d1d77298c347507c51be1ee1b2375 Unapplied parent: 4d3f2d83da5663fd03d7ace3c4c5054bdac13151 New changelog entries: * New upstream release (LP: #1449369). * Rebased patches for 2.0.12 onto 2.0.13.
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 00feb6c..e4c1c45 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -14,6 +14,8 @@
#
import unittest
+import tempfile
+import os
from env import waagent
sample_mount_list = """\
@@ -43,5 +45,39 @@ class TestWAAgentUtils(unittest.TestCase):
mp = waagent.GetMountPoint(malformed, device_name)
self.assertEqual(mp, None)
+ def test_replace_in_file_found(self):
+ tmpfilename = tempfile.mkstemp('', 'tmp', None, True)[1]
+ try:
+ tmpfile = open(tmpfilename, 'w')
+ tmpfile.write('Replace Me')
+ tmpfile.close()
+
+ result = waagent.ReplaceStringInFile(tmpfilename, r'c. ', 'ced ')
+
+ tmpfile = open(tmpfilename, 'r')
+ newcontents = tmpfile.read();
+ tmpfile.close()
+
+ self.assertEqual('Replaced Me', str(newcontents))
+ finally:
+ os.remove(tmpfilename)
+
+ def test_replace_in_file_not_found(self):
+ tmpfilename = tempfile.mkstemp('', 'tmp', None, True)[1]
+ try:
+ tmpfile = open(tmpfilename, 'w')
+ tmpfile.write('Replace Me')
+ tmpfile.close()
+
+ result = waagent.ReplaceStringInFile(tmpfilename, r'not here ', 'ced ')
+
+ tmpfile = open(tmpfilename, 'r')
+ newcontents = tmpfile.read();
+ tmpfile.close()
+
+ self.assertEqual('Replace Me', str(newcontents))
+ finally:
+ os.remove(tmpfilename)
+
if __name__ == '__main__':
unittest.main()