1
# Copyright 2014 Microsoft Corporation
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
15
# Requires Python 2.4+ and Openssl 1.0+
17
# Implements parts of RFC 2131, 1541, 1497 and
18
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
19
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
22
import tests.tools as tools
26
import azurelinuxagent.utils.fileutil as fileutil
29
class TestFileOperations(unittest.TestCase):
30
def test_get_set_file_contents(self):
31
test_file='/tmp/test_file'
32
content = str(uuid.uuid4())
33
fileutil.SetFileContents(test_file, content)
34
self.assertTrue(tools.simple_file_grep(test_file, content))
35
self.assertEquals(content, fileutil.GetFileContents('/tmp/test_file'))
38
def test_append_file(self):
39
test_file='/tmp/test_file2'
40
content = str(uuid.uuid4())
41
fileutil.AppendFileContents(test_file, content)
42
self.assertTrue(tools.simple_file_grep(test_file, content))
45
def test_replace_file(self):
46
test_file='/tmp/test_file3'
47
contentOld = str(uuid.uuid4())
48
content = str(uuid.uuid4())
49
with open(test_file, "a+") as F:
51
fileutil.ReplaceFileContentsAtomic(test_file, content)
52
self.assertFalse(tools.simple_file_grep(test_file, contentOld))
53
self.assertTrue(tools.simple_file_grep(test_file, content))
56
def test_get_last_path_element(self):
57
filepath = '/tmp/abc.def'
58
filename = fileutil.GetLastPathElement(filepath)
59
self.assertEquals('abc.def', filename)
62
filename = fileutil.GetLastPathElement(filepath)
63
self.assertEquals('abc', filename)
65
if __name__ == '__main__':