diff options
Diffstat (limited to 'tests/test_repo_trace.py')
-rw-r--r-- | tests/test_repo_trace.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_repo_trace.py b/tests/test_repo_trace.py new file mode 100644 index 00000000..5faf2938 --- /dev/null +++ b/tests/test_repo_trace.py | |||
@@ -0,0 +1,56 @@ | |||
1 | # Copyright 2022 The Android Open Source Project | ||
2 | # | ||
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 | ||
6 | # | ||
7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | # | ||
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. | ||
14 | |||
15 | """Unittests for the repo_trace.py module.""" | ||
16 | |||
17 | import os | ||
18 | import unittest | ||
19 | from unittest import mock | ||
20 | |||
21 | import repo_trace | ||
22 | |||
23 | |||
24 | class TraceTests(unittest.TestCase): | ||
25 | """Check Trace behavior.""" | ||
26 | |||
27 | def testTrace_MaxSizeEnforced(self): | ||
28 | content = 'git chicken' | ||
29 | |||
30 | with repo_trace.Trace(content, first_trace=True): | ||
31 | pass | ||
32 | first_trace_size = os.path.getsize(repo_trace._TRACE_FILE) | ||
33 | |||
34 | with repo_trace.Trace(content): | ||
35 | pass | ||
36 | self.assertGreater( | ||
37 | os.path.getsize(repo_trace._TRACE_FILE), first_trace_size) | ||
38 | |||
39 | # Check we clear everything is the last chunk is larger than _MAX_SIZE. | ||
40 | with mock.patch('repo_trace._MAX_SIZE', 0): | ||
41 | with repo_trace.Trace(content, first_trace=True): | ||
42 | pass | ||
43 | self.assertEqual(first_trace_size, | ||
44 | os.path.getsize(repo_trace._TRACE_FILE)) | ||
45 | |||
46 | # Check we only clear the chunks we need to. | ||
47 | repo_trace._MAX_SIZE = (first_trace_size + 1) / (1024 * 1024) | ||
48 | with repo_trace.Trace(content, first_trace=True): | ||
49 | pass | ||
50 | self.assertEqual(first_trace_size * 2, | ||
51 | os.path.getsize(repo_trace._TRACE_FILE)) | ||
52 | |||
53 | with repo_trace.Trace(content, first_trace=True): | ||
54 | pass | ||
55 | self.assertEqual(first_trace_size * 2, | ||
56 | os.path.getsize(repo_trace._TRACE_FILE)) | ||