Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: client/tests/isolated_format_test.py

Issue 2844063005: Add option to collapse symlinks in isolate.py (Closed)
Patch Set: Add -L Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/tests/isolate_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The LUCI Authors. All rights reserved. 2 # Copyright 2014 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import logging 8 import logging
9 import os 9 import os
10 import sys 10 import sys
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 ] 82 ]
83 self.assertEqual(expected, actual) 83 self.assertEqual(expected, actual)
84 84
85 def test_file_to_metadata_path_case_simple(self): 85 def test_file_to_metadata_path_case_simple(self):
86 # Ensure the symlink dest is saved in the right path case. 86 # Ensure the symlink dest is saved in the right path case.
87 subdir = os.path.join(self.cwd, 'subdir') 87 subdir = os.path.join(self.cwd, 'subdir')
88 os.mkdir(subdir) 88 os.mkdir(subdir)
89 linkdir = os.path.join(self.cwd, 'linkdir') 89 linkdir = os.path.join(self.cwd, 'linkdir')
90 os.symlink('subDir', linkdir) 90 os.symlink('subDir', linkdir)
91 actual = isolated_format.file_to_metadata( 91 actual = isolated_format.file_to_metadata(
92 unicode(linkdir.upper()), {}, True, ALGO) 92 unicode(linkdir.upper()), {}, True, ALGO, False)
93 expected = {'l': u'subdir', 't': int(os.stat(linkdir).st_mtime)} 93 expected = {'l': u'subdir', 't': int(os.stat(linkdir).st_mtime)}
94 self.assertEqual(expected, actual) 94 self.assertEqual(expected, actual)
95 95
96 def test_file_to_metadata_path_case_complex(self): 96 def test_file_to_metadata_path_case_complex(self):
97 # Ensure the symlink dest is saved in the right path case. This includes 2 97 # Ensure the symlink dest is saved in the right path case. This includes 2
98 # layers of symlinks. 98 # layers of symlinks.
99 basedir = os.path.join(self.cwd, 'basebir') 99 basedir = os.path.join(self.cwd, 'basebir')
100 os.mkdir(basedir) 100 os.mkdir(basedir)
101 101
102 linkeddir2 = os.path.join(self.cwd, 'linkeddir2') 102 linkeddir2 = os.path.join(self.cwd, 'linkeddir2')
103 os.mkdir(linkeddir2) 103 os.mkdir(linkeddir2)
104 104
105 linkeddir1 = os.path.join(basedir, 'linkeddir1') 105 linkeddir1 = os.path.join(basedir, 'linkeddir1')
106 os.symlink('../linkedDir2', linkeddir1) 106 os.symlink('../linkedDir2', linkeddir1)
107 107
108 subsymlinkdir = os.path.join(basedir, 'symlinkdir') 108 subsymlinkdir = os.path.join(basedir, 'symlinkdir')
109 os.symlink('linkedDir1', subsymlinkdir) 109 os.symlink('linkedDir1', subsymlinkdir)
110 110
111 actual = isolated_format.file_to_metadata( 111 actual = isolated_format.file_to_metadata(
112 unicode(subsymlinkdir.upper()), {}, True, ALGO) 112 unicode(subsymlinkdir.upper()), {}, True, ALGO, False)
113 expected = { 113 expected = {
114 'l': u'linkeddir1', 't': int(os.stat(subsymlinkdir).st_mtime), 114 'l': u'linkeddir1', 't': int(os.stat(subsymlinkdir).st_mtime),
115 } 115 }
116 self.assertEqual(expected, actual) 116 self.assertEqual(expected, actual)
117 117
118 actual = isolated_format.file_to_metadata( 118 actual = isolated_format.file_to_metadata(
119 unicode(linkeddir1.upper()), {}, True, ALGO) 119 unicode(linkeddir1.upper()), {}, True, ALGO, False)
120 expected = { 120 expected = {
121 'l': u'../linkeddir2', 't': int(os.stat(linkeddir1).st_mtime), 121 'l': u'../linkeddir2', 't': int(os.stat(linkeddir1).st_mtime),
122 } 122 }
123 self.assertEqual(expected, actual) 123 self.assertEqual(expected, actual)
124 124
125 if sys.platform != 'win32': 125 if sys.platform != 'win32':
126 def test_symlink_input_absolute_path(self): 126 def test_symlink_input_absolute_path(self):
127 # A symlink is outside of the checkout, it should be treated as a normal 127 # A symlink is outside of the checkout, it should be treated as a normal
128 # directory. 128 # directory.
129 # .../src 129 # .../src
130 # .../src/out -> .../tmp/foo 130 # .../src/out -> .../tmp/foo
131 # .../tmp 131 # .../tmp
132 # .../tmp/foo 132 # .../tmp/foo
133 src = os.path.join(self.cwd, u'src') 133 src = os.path.join(self.cwd, u'src')
134 src_out = os.path.join(src, 'out') 134 src_out = os.path.join(src, 'out')
135 tmp = os.path.join(self.cwd, 'tmp') 135 tmp = os.path.join(self.cwd, 'tmp')
136 tmp_foo = os.path.join(tmp, 'foo') 136 tmp_foo = os.path.join(tmp, 'foo')
137 os.mkdir(src) 137 os.mkdir(src)
138 os.mkdir(tmp) 138 os.mkdir(tmp)
139 os.mkdir(tmp_foo) 139 os.mkdir(tmp_foo)
140 # The problem was that it's an absolute path, so it must be considered a 140 # The problem was that it's an absolute path, so it must be considered a
141 # normal directory. 141 # normal directory.
142 os.symlink(tmp, src_out) 142 os.symlink(tmp, src_out)
143 open(os.path.join(tmp_foo, 'bar.txt'), 'w').close() 143 open(os.path.join(tmp_foo, 'bar.txt'), 'w').close()
144 actual = isolated_format.expand_symlinks(src, u'out/foo/bar.txt') 144 actual = isolated_format.expand_symlinks(src, u'out/foo/bar.txt')
145 self.assertEqual((u'out/foo/bar.txt', []), actual) 145 self.assertEqual((u'out/foo/bar.txt', []), actual)
146 146
147 def test_file_to_metadata_path_case_collapse(self):
148 # Ensure setting the collapse_symlink option doesn't include the symlinks
149 basedir = os.path.join(self.cwd, 'basedir')
150 os.mkdir(basedir)
151 subdir = os.path.join(basedir, 'subdir')
152 os.mkdir(subdir)
153 linkdir = os.path.join(basedir, 'linkdir')
154 os.mkdir(linkdir)
155
156 foo_file = os.path.join(subdir, 'Foo.txt')
157 open(foo_file, 'w').close()
158 sym_file = os.path.join(basedir, 'linkdir', 'Sym.txt')
159 os.symlink('../subdir/Foo.txt', sym_file)
160
161 actual = isolated_format.file_to_metadata(sym_file, {}, True, ALGO, True)
162
163 expected = {
164 # SHA-1 of empty string
165 'h': 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
166 'm': 288,
167 's': 0,
168 't': int(round(os.stat(foo_file).st_mtime)),
169 }
170 self.assertEqual(expected, actual)
171
147 172
148 class TestIsolated(auto_stub.TestCase): 173 class TestIsolated(auto_stub.TestCase):
149 def test_load_isolated_empty(self): 174 def test_load_isolated_empty(self):
150 m = isolated_format.load_isolated('{}', isolateserver_mock.ALGO) 175 m = isolated_format.load_isolated('{}', isolateserver_mock.ALGO)
151 self.assertEqual({}, m) 176 self.assertEqual({}, m)
152 177
153 def test_load_isolated_good(self): 178 def test_load_isolated_good(self):
154 data = { 179 data = {
155 u'command': [u'foo', u'bar'], 180 u'command': [u'foo', u'bar'],
156 u'files': { 181 u'files': {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 self.assertEqual([('foo', data, True)], calls) 274 self.assertEqual([('foo', data, True)], calls)
250 275
251 276
252 if __name__ == '__main__': 277 if __name__ == '__main__':
253 fix_encoding.fix_encoding() 278 fix_encoding.fix_encoding()
254 if '-v' in sys.argv: 279 if '-v' in sys.argv:
255 unittest.TestCase.maxDiff = None 280 unittest.TestCase.maxDiff = None
256 logging.basicConfig( 281 logging.basicConfig(
257 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR)) 282 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR))
258 unittest.main() 283 unittest.main()
OLDNEW
« no previous file with comments | « client/tests/isolate_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698