| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 11 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 14 # limitations under the License. | 14 # limitations under the License. |
| 15 """Integration tests for mv command.""" | 15 """Integration tests for mv command.""" |
| 16 | 16 |
| 17 from __future__ import absolute_import | 17 from __future__ import absolute_import |
| 18 | 18 |
| 19 import os | 19 import os |
| 20 | 20 |
| 21 import gslib.tests.testcase as testcase | 21 import gslib.tests.testcase as testcase |
| 22 from gslib.tests.util import ObjectToURI as suri | 22 from gslib.tests.util import ObjectToURI as suri |
| 23 from gslib.tests.util import PerformsFileToObjectUpload | 23 from gslib.tests.util import SequentialAndParallelTransfer |
| 24 from gslib.util import Retry | 24 from gslib.util import Retry |
| 25 | 25 |
| 26 | 26 |
| 27 class TestMv(testcase.GsUtilIntegrationTestCase): | 27 class TestMv(testcase.GsUtilIntegrationTestCase): |
| 28 """Integration tests for mv command.""" | 28 """Integration tests for mv command.""" |
| 29 | 29 |
| 30 def test_moving(self): | 30 def test_moving(self): |
| 31 """Tests moving two buckets, one with 2 objects and one with 0 objects.""" | 31 """Tests moving two buckets, one with 2 objects and one with 0 objects.""" |
| 32 bucket1_uri = self.CreateBucket(test_objects=2) | 32 bucket1_uri = self.CreateBucket(test_objects=2) |
| 33 self.AssertNObjectsInBucket(bucket1_uri, 2) | 33 self.AssertNObjectsInBucket(bucket1_uri, 2) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 self.AssertNObjectsInBucket(bucket1_uri, 1) | 70 self.AssertNObjectsInBucket(bucket1_uri, 1) |
| 71 self.AssertNObjectsInBucket(bucket2_uri, 0) | 71 self.AssertNObjectsInBucket(bucket2_uri, 0) |
| 72 | 72 |
| 73 def test_move_dir_to_bucket(self): | 73 def test_move_dir_to_bucket(self): |
| 74 """Tests moving a local directory to a bucket.""" | 74 """Tests moving a local directory to a bucket.""" |
| 75 bucket_uri = self.CreateBucket() | 75 bucket_uri = self.CreateBucket() |
| 76 dir_to_move = self.CreateTempDir(test_files=2) | 76 dir_to_move = self.CreateTempDir(test_files=2) |
| 77 self.RunGsUtil(['mv', dir_to_move, suri(bucket_uri)]) | 77 self.RunGsUtil(['mv', dir_to_move, suri(bucket_uri)]) |
| 78 self.AssertNObjectsInBucket(bucket_uri, 2) | 78 self.AssertNObjectsInBucket(bucket_uri, 2) |
| 79 | 79 |
| 80 @PerformsFileToObjectUpload | 80 @SequentialAndParallelTransfer |
| 81 def test_stdin_args(self): | 81 def test_stdin_args(self): |
| 82 """Tests mv with the -I option.""" | 82 """Tests mv with the -I option.""" |
| 83 tmpdir = self.CreateTempDir() | 83 tmpdir = self.CreateTempDir() |
| 84 fpath1 = self.CreateTempFile(tmpdir=tmpdir, contents='data1') | 84 fpath1 = self.CreateTempFile(tmpdir=tmpdir, contents='data1') |
| 85 fpath2 = self.CreateTempFile(tmpdir=tmpdir, contents='data2') | 85 fpath2 = self.CreateTempFile(tmpdir=tmpdir, contents='data2') |
| 86 bucket_uri = self.CreateBucket() | 86 bucket_uri = self.CreateBucket() |
| 87 self.RunGsUtil(['mv', '-I', suri(bucket_uri)], | 87 self.RunGsUtil(['mv', '-I', suri(bucket_uri)], |
| 88 stdin='\n'.join((fpath1, fpath2))) | 88 stdin='\n'.join((fpath1, fpath2))) |
| 89 | 89 |
| 90 # Use @Retry as hedge against bucket listing eventual consistency. | 90 # Use @Retry as hedge against bucket listing eventual consistency. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 103 object_uri = self.CreateObject(bucket_uri=bucket_uri, contents='data2') | 103 object_uri = self.CreateObject(bucket_uri=bucket_uri, contents='data2') |
| 104 stderr = self.RunGsUtil(['mv', '-n', fpath1, suri(object_uri)], | 104 stderr = self.RunGsUtil(['mv', '-n', fpath1, suri(object_uri)], |
| 105 return_stderr=True) | 105 return_stderr=True) |
| 106 # Copy should be skipped and source file should not be removed. | 106 # Copy should be skipped and source file should not be removed. |
| 107 self.assertIn('Skipping existing item: %s' % suri(object_uri), stderr) | 107 self.assertIn('Skipping existing item: %s' % suri(object_uri), stderr) |
| 108 self.assertNotIn('Removing %s' % suri(fpath1), stderr) | 108 self.assertNotIn('Removing %s' % suri(fpath1), stderr) |
| 109 # Object content should be unchanged. | 109 # Object content should be unchanged. |
| 110 contents = self.RunGsUtil(['cat', suri(object_uri)], return_stdout=True) | 110 contents = self.RunGsUtil(['cat', suri(object_uri)], return_stdout=True) |
| 111 self.assertEqual(contents, 'data2') | 111 self.assertEqual(contents, 'data2') |
| 112 | 112 |
| OLD | NEW |