| Index: gslib/tests/test_du.py
|
| ===================================================================
|
| --- gslib/tests/test_du.py (revision 33376)
|
| +++ gslib/tests/test_du.py (working copy)
|
| @@ -1,3 +1,4 @@
|
| +# -*- coding: utf-8 -*-
|
| # Copyright 2013 Google Inc. All Rights Reserved.
|
| #
|
| # Licensed under the Apache License, Version 2.0 (the "License");
|
| @@ -11,16 +12,21 @@
|
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| # See the License for the specific language governing permissions and
|
| # limitations under the License.
|
| +"""Tests for du command."""
|
|
|
| +from __future__ import absolute_import
|
| +
|
| import gslib.tests.testcase as testcase
|
| +from gslib.tests.testcase.integration_testcase import SkipForS3
|
| +from gslib.tests.util import ObjectToURI as suri
|
| from gslib.util import Retry
|
| -from gslib.tests.util import ObjectToURI as suri
|
|
|
|
|
| class TestDu(testcase.GsUtilIntegrationTestCase):
|
| """Integration tests for du command."""
|
|
|
| def _create_nested_subdir(self):
|
| + """Creates a nested subdirectory for use by tests in this module."""
|
| bucket_uri = self.CreateBucket()
|
| obj_uris = []
|
| obj_uris.append(self.CreateObject(
|
| @@ -53,6 +59,7 @@
|
| _Check()
|
|
|
| def test_subdirs(self):
|
| + """Tests that subdirectory sizes are correctly calculated and listed."""
|
| bucket_uri, obj_uris = self._create_nested_subdir()
|
|
|
| # Use @Retry as hedge against bucket listing eventual consistency.
|
| @@ -70,6 +77,7 @@
|
| _Check()
|
|
|
| def test_multi_args(self):
|
| + """Tests running du with multiple command line arguments."""
|
| bucket_uri = self.CreateBucket()
|
| obj_uri1 = self.CreateObject(bucket_uri=bucket_uri, contents='foo')
|
| obj_uri2 = self.CreateObject(bucket_uri=bucket_uri, contents='foo2')
|
| @@ -85,6 +93,7 @@
|
| _Check()
|
|
|
| def test_total(self):
|
| + """Tests total size listing via the -c flag."""
|
| bucket_uri = self.CreateBucket()
|
| obj_uri1 = self.CreateObject(bucket_uri=bucket_uri, contents='foo')
|
| obj_uri2 = self.CreateObject(bucket_uri=bucket_uri, contents='zebra')
|
| @@ -110,6 +119,7 @@
|
| _Check()
|
|
|
| def test_summary(self):
|
| + """Tests summary listing with the -s flag."""
|
| bucket_uri1, _ = self._create_nested_subdir()
|
| bucket_uri2, _ = self._create_nested_subdir()
|
|
|
| @@ -124,7 +134,27 @@
|
| ]))
|
| _Check()
|
|
|
| + def test_subdir_summary(self):
|
| + """Tests summary listing with the -s flag on a subdirectory."""
|
| + bucket_uri1, _ = self._create_nested_subdir()
|
| + bucket_uri2, _ = self._create_nested_subdir()
|
| + subdir1 = suri(bucket_uri1, 'sub1')
|
| + subdir2 = suri(bucket_uri2, 'sub1')
|
| +
|
| + # Use @Retry as hedge against bucket listing eventual consistency.
|
| + @Retry(AssertionError, tries=3, timeout_secs=1)
|
| + def _Check():
|
| + stdout = self.RunGsUtil(
|
| + ['du', '-s', subdir1, subdir2], return_stdout=True)
|
| + self.assertSetEqual(set(stdout.splitlines()), set([
|
| + '%-10s %s' % (18, subdir1),
|
| + '%-10s %s' % (18, subdir2),
|
| + ]))
|
| + _Check()
|
| +
|
| + @SkipForS3('S3 lists versions in reverse order.')
|
| def test_versioned(self):
|
| + """Tests listing all versions with the -a flag."""
|
| bucket_uri = self.CreateVersionedBucket()
|
| object_uri1 = self.CreateObject(
|
| bucket_uri=bucket_uri, object_name='foo', contents='foo')
|
| @@ -152,6 +182,7 @@
|
| _Check2()
|
|
|
| def test_null_endings(self):
|
| + """Tests outputting 0-endings with the -0 flag."""
|
| bucket_uri = self.CreateBucket()
|
| obj_uri1 = self.CreateObject(bucket_uri=bucket_uri, contents='foo')
|
| obj_uri2 = self.CreateObject(bucket_uri=bucket_uri, contents='zebra')
|
| @@ -169,6 +200,7 @@
|
| _Check()
|
|
|
| def test_excludes(self):
|
| + """Tests exclude pattern excluding certain file paths."""
|
| bucket_uri, obj_uris = self._create_nested_subdir()
|
|
|
| # Use @Retry as hedge against bucket listing eventual consistency.
|
| @@ -186,6 +218,7 @@
|
| _Check()
|
|
|
| def test_excludes_file(self):
|
| + """Tests file exclusion with the -X flag."""
|
| bucket_uri, obj_uris = self._create_nested_subdir()
|
| fpath = self.CreateTempFile(contents='*sub2/five*\n*sub1/four')
|
|
|
|
|