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

Side by Side Diff: third_party/gsutil/gslib/tests/test_rm.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 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
OLDNEW
(Empty)
1 # Copyright 2013 Google Inc. All Rights Reserved.
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 import gslib.tests.testcase as testcase
16 from gslib.util import Retry
17 from gslib.tests.util import ObjectToURI as suri
18
19
20 class TestRm(testcase.GsUtilIntegrationTestCase):
21 """Integration tests for rm command."""
22
23 def test_all_versions_current(self):
24 """Test that 'rm -a' for an object with a current version works."""
25 bucket_uri = self.CreateVersionedBucket()
26 key_uri = bucket_uri.clone_replace_name('foo')
27 key_uri.set_contents_from_string('bar')
28 g1 = key_uri.generation
29 key_uri.set_contents_from_string('baz')
30 g2 = key_uri.generation
31 stderr = self.RunGsUtil(['-m', 'rm', '-a', suri(key_uri)],
32 return_stderr=True)
33 self.assertEqual(stderr.count('Removing gs://'), 2)
34 self.assertIn('Removing %s#%s...' % (suri(key_uri), g1), stderr)
35 self.assertIn('Removing %s#%s...' % (suri(key_uri), g2), stderr)
36 # Use @Retry as hedge against bucket listing eventual consistency.
37 @Retry(AssertionError, tries=3, delay=1, backoff=1)
38 def _Check1():
39 stdout = self.RunGsUtil(['ls', '-a', suri(bucket_uri)],
40 return_stdout=True)
41 self.assertEqual(stdout, '')
42 _Check1()
43
44 def test_all_versions_no_current(self):
45 """Test that 'rm -a' for an object without a current version works."""
46 bucket_uri = self.CreateVersionedBucket()
47 key_uri = bucket_uri.clone_replace_name('foo')
48 key_uri.set_contents_from_string('bar')
49 g1 = key_uri.generation
50 key_uri.set_contents_from_string('baz')
51 g2 = key_uri.generation
52 stderr = self.RunGsUtil(['rm', suri(key_uri)], return_stderr=True)
53 self.assertEqual(stderr.count('Removing gs://'), 1)
54 self.assertIn('Removing %s...' % suri(key_uri), stderr)
55 stderr = self.RunGsUtil(['-m', 'rm', '-a', suri(key_uri)],
56 return_stderr=True)
57 self.assertEqual(stderr.count('Removing gs://'), 2)
58 self.assertIn('Removing %s#%s...' % (suri(key_uri), g1), stderr)
59 self.assertIn('Removing %s#%s...' % (suri(key_uri), g2), stderr)
60 # Use @Retry as hedge against bucket listing eventual consistency.
61 @Retry(AssertionError, tries=3, delay=1, backoff=1)
62 def _Check1():
63 stdout = self.RunGsUtil(['ls', '-a', suri(bucket_uri)],
64 return_stdout=True)
65 self.assertEqual(stdout, '')
66 _Check1()
67
68 def test_fails_for_missing_obj(self):
69 bucket_uri = self.CreateVersionedBucket()
70 stderr = self.RunGsUtil(['rm', '-a', '%s/foo' % suri(bucket_uri)],
71 return_stderr=True, expected_status=1)
72 self.assertIn('Not Found', stderr)
73
74 def test_remove_all_versions_recursive_on_bucket(self):
75 """Test that 'rm -ar' works on bucket."""
76 bucket_uri = self.CreateVersionedBucket()
77 k1_uri = bucket_uri.clone_replace_name('foo')
78 k2_uri = bucket_uri.clone_replace_name('foo2')
79 k1_uri.set_contents_from_string('bar')
80 k2_uri.set_contents_from_string('bar2')
81 k1g1 = k1_uri.generation
82 k2g1 = k2_uri.generation
83 k1_uri.set_contents_from_string('baz')
84 k2_uri.set_contents_from_string('baz2')
85 k1g2 = k1_uri.generation
86 k2g2 = k2_uri.generation
87
88 stderr = self.RunGsUtil(['rm', '-ar', suri(bucket_uri)],
89 return_stderr=True)
90 self.assertEqual(stderr.count('Removing gs://'), 4)
91 self.assertIn('Removing %s#%s...' % (suri(k1_uri), k1g1), stderr)
92 self.assertIn('Removing %s#%s...' % (suri(k1_uri), k1g2), stderr)
93 self.assertIn('Removing %s#%s...' % (suri(k2_uri), k2g1), stderr)
94 self.assertIn('Removing %s#%s...' % (suri(k2_uri), k2g2), stderr)
95 # Use @Retry as hedge against bucket listing eventual consistency.
96 @Retry(AssertionError, tries=3, delay=1, backoff=1)
97 def _Check1():
98 stdout = self.RunGsUtil(['ls', '-a', suri(bucket_uri)],
99 return_stdout=True)
100 self.assertEqual(stdout, '')
101 _Check1()
102
103 def test_remove_all_versions_recursive_on_subdir(self):
104 """Test that 'rm -ar' works on subdir."""
105 bucket_uri = self.CreateVersionedBucket()
106 k1_uri = bucket_uri.clone_replace_name('dir/foo')
107 k2_uri = bucket_uri.clone_replace_name('dir/foo2')
108 k1_uri.set_contents_from_string('bar')
109 k2_uri.set_contents_from_string('bar2')
110 k1g1 = k1_uri.generation
111 k2g1 = k2_uri.generation
112 k1_uri.set_contents_from_string('baz')
113 k2_uri.set_contents_from_string('baz2')
114 k1g2 = k1_uri.generation
115 k2g2 = k2_uri.generation
116
117 stderr = self.RunGsUtil(['rm', '-ar', '%s/dir' % suri(bucket_uri)],
118 return_stderr=True)
119 self.assertEqual(stderr.count('Removing gs://'), 4)
120 self.assertIn('Removing %s#%s...' % (suri(k1_uri), k1g1), stderr)
121 self.assertIn('Removing %s#%s...' % (suri(k1_uri), k1g2), stderr)
122 self.assertIn('Removing %s#%s...' % (suri(k2_uri), k2g1), stderr)
123 self.assertIn('Removing %s#%s...' % (suri(k2_uri), k2g2), stderr)
124 # Use @Retry as hedge against bucket listing eventual consistency.
125 @Retry(AssertionError, tries=3, delay=1, backoff=1)
126 def _Check1():
127 stdout = self.RunGsUtil(['ls', '-a', suri(bucket_uri)],
128 return_stdout=True)
129 self.assertEqual(stdout, '')
130 _Check1()
131
132 def test_some_missing(self):
133 """Test that 'rm -a' fails when some but not all uris don't exist."""
134 bucket_uri = self.CreateVersionedBucket()
135 key_uri = bucket_uri.clone_replace_name('foo')
136 key_uri.set_contents_from_string('bar')
137 stderr = self.RunGsUtil(['rm', '-a', suri(key_uri), '%s/missing'
138 % suri(bucket_uri)],
139 return_stderr=True, expected_status=1)
140 self.assertEqual(stderr.count('Removing gs://'), 2)
141 self.assertIn('Not Found', stderr)
142
143 def test_some_missing_force(self):
144 """Test that 'rm -af' succeeds despite hidden first uri."""
145 bucket_uri = self.CreateVersionedBucket()
146 key_uri = bucket_uri.clone_replace_name('foo')
147 key_uri.set_contents_from_string('bar')
148 stderr = self.RunGsUtil(['rm', '-af', suri(key_uri), '%s/missing'
149 % suri(bucket_uri)], return_stderr=True)
150 self.assertEqual(stderr.count('Removing gs://'), 2)
151 # Use @Retry as hedge against bucket listing eventual consistency.
152 @Retry(AssertionError, tries=3, delay=1, backoff=1)
153 def _Check1():
154 stdout = self.RunGsUtil(['ls', '-a', suri(bucket_uri)],
155 return_stdout=True)
156 self.assertEqual(stdout, '')
157 _Check1()
158
159 def test_folder_objects_deleted(self):
160 """Test for 'rm -r' of a folder with a dir_$folder$ marker."""
161 bucket_uri = self.CreateVersionedBucket()
162 key_uri = bucket_uri.clone_replace_name('abc/o1')
163 key_uri.set_contents_from_string('foobar')
164 folderkey = bucket_uri.clone_replace_name('abc_$folder$')
165 folderkey.set_contents_from_string('')
166 stderr = self.RunGsUtil(['rm', '-r', '%s/abc' % suri(bucket_uri)],
167 return_stderr=True)
168 self.assertEqual(stderr.count('Removing gs://'), 2)
169 # Use @Retry as hedge against bucket listing eventual consistency.
170 @Retry(AssertionError, tries=3, delay=1, backoff=1)
171 def _Check1():
172 stdout = self.RunGsUtil(['ls', suri(bucket_uri)], return_stdout=True)
173 self.assertEqual(stdout, '')
174 _Check1()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698