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

Side by Side Diff: third_party/gsutil/gslib/tests/test_mv.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 TestMv(testcase.GsUtilIntegrationTestCase):
21 """Integration tests for mv command."""
22
23 def test_moving(self):
24 # Create two buckets, one with 2 objects and one with 0 objects, and verify.
25 bucket1_uri = self.CreateBucket(test_objects=2)
26 # Use @Retry as hedge against bucket listing eventual consistency.
27 @Retry(AssertionError, tries=3, delay=1, backoff=1)
28 def _Check1():
29 stdout = self.RunGsUtil(['ls', suri(bucket1_uri)], return_stdout=True)
30 self.assertNumLines(stdout, 2)
31 _Check1()
32 bucket2_uri = self.CreateBucket()
33 # Use @Retry as hedge against bucket listing eventual consistency.
34 @Retry(AssertionError, tries=3, delay=1, backoff=1)
35 def _Check2():
36 stdout = self.RunGsUtil(['ls', suri(bucket2_uri)], return_stdout=True)
37 self.assertNumLines(stdout, 0)
38 _Check2()
39
40 # Move two objects from bucket1 to bucket2.
41 objs = [bucket1_uri.clone_replace_key(key).versionless_uri
42 for key in bucket1_uri.list_bucket()]
43 cmd = (['-m', 'mv'] + objs + [suri(bucket2_uri)])
44 stderr = self.RunGsUtil(cmd, return_stderr=True)
45 self.assertEqual(stderr.count('Copying'), 2)
46 self.assertEqual(stderr.count('Removing'), 2)
47
48 # Verify objects were moved.
49 # Use @Retry as hedge against bucket listing eventual consistency.
50 @Retry(AssertionError, tries=3, delay=1, backoff=1)
51 def _Check3():
52 stdout = self.RunGsUtil(['ls', suri(bucket1_uri)], return_stdout=True)
53 self.assertNumLines(stdout, 0)
54 stdout = self.RunGsUtil(['ls', suri(bucket2_uri)], return_stdout=True)
55 self.assertNumLines(stdout, 2)
56 _Check3()
57
58 # Remove one of the objects.
59 objs = [bucket2_uri.clone_replace_key(key).versionless_uri
60 for key in bucket2_uri.list_bucket()]
61 obj1 = objs[0]
62 self.RunGsUtil(['rm', obj1])
63
64 # Verify there are now 1 and 0 objects.
65 # Use @Retry as hedge against bucket listing eventual consistency.
66 @Retry(AssertionError, tries=3, delay=1, backoff=1)
67 def _Check4():
68 stdout = self.RunGsUtil(['ls', suri(bucket1_uri)], return_stdout=True)
69 self.assertNumLines(stdout, 0)
70 stdout = self.RunGsUtil(['ls', suri(bucket2_uri)], return_stdout=True)
71 self.assertNumLines(stdout, 1)
72 _Check4()
73
74 # Move the 1 remaining object back.
75 objs = [suri(bucket2_uri.clone_replace_key(key))
76 for key in bucket2_uri.list_bucket()]
77 cmd = (['-m', 'mv'] + objs + [suri(bucket1_uri)])
78 stderr = self.RunGsUtil(cmd, return_stderr=True)
79 self.assertEqual(stderr.count('Copying'), 1)
80 self.assertEqual(stderr.count('Removing'), 1)
81
82 # Verify object moved.
83 # Use @Retry as hedge against bucket listing eventual consistency.
84 @Retry(AssertionError, tries=3, delay=1, backoff=1)
85 def _Check5():
86 stdout = self.RunGsUtil(['ls', suri(bucket1_uri)], return_stdout=True)
87 self.assertNumLines(stdout, 1)
88 stdout = self.RunGsUtil(['ls', suri(bucket2_uri)], return_stdout=True)
89 self.assertNumLines(stdout, 0)
90 _Check5()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698