OLD | NEW |
(Empty) | |
| 1 # -*- coding: utf-8 -*- |
| 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (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 |
| 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software |
| 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 # See the License for the specific language governing permissions and |
| 14 # limitations under the License. |
| 15 """Integration tests for gsutil -D option.""" |
| 16 |
| 17 from __future__ import absolute_import |
| 18 |
| 19 import gslib |
| 20 from gslib.cs_api_map import ApiSelector |
| 21 import gslib.tests.testcase as testcase |
| 22 from gslib.tests.testcase.integration_testcase import SkipForS3 |
| 23 from gslib.tests.util import ObjectToURI as suri |
| 24 from gslib.tests.util import SetBotoConfigForTest |
| 25 from gslib.util import ONE_KIB |
| 26 |
| 27 |
| 28 @SkipForS3('-D output is implementation-specific.') |
| 29 class TestDOption(testcase.GsUtilIntegrationTestCase): |
| 30 """Integration tests for gsutil -D option.""" |
| 31 |
| 32 def test_minus_D_multipart_upload(self): |
| 33 """Tests that debug option does not output upload media body.""" |
| 34 # We want to ensure it works with and without a trailing newline. |
| 35 for file_contents in ('a1b2c3d4', 'a1b2c3d4\n'): |
| 36 fpath = self.CreateTempFile(contents=file_contents) |
| 37 bucket_uri = self.CreateBucket() |
| 38 with SetBotoConfigForTest( |
| 39 [('GSUtil', 'resumable_threshold', str(ONE_KIB))]): |
| 40 stderr = self.RunGsUtil( |
| 41 ['-D', 'cp', fpath, suri(bucket_uri)], return_stderr=True) |
| 42 print 'command line:' + ' '.join(['-D', 'cp', fpath, suri(bucket_uri)]) |
| 43 if self.test_api == ApiSelector.JSON: |
| 44 self.assertIn('media body', stderr) |
| 45 self.assertNotIn('a1b2c3d4', stderr) |
| 46 self.assertIn('Comparing local vs cloud md5-checksum for', stderr) |
| 47 self.assertIn('total_bytes_transferred: %d' % len(file_contents), |
| 48 stderr) |
| 49 |
| 50 def test_minus_D_resumable_upload(self): |
| 51 fpath = self.CreateTempFile(contents='a1b2c3d4') |
| 52 bucket_uri = self.CreateBucket() |
| 53 with SetBotoConfigForTest([('GSUtil', 'resumable_threshold', '4')]): |
| 54 stderr = self.RunGsUtil( |
| 55 ['-D', 'cp', fpath, suri(bucket_uri)], return_stderr=True) |
| 56 self.assertNotIn('a1b2c3d4', stderr) |
| 57 self.assertIn('Comparing local vs cloud md5-checksum for', stderr) |
| 58 self.assertIn('total_bytes_transferred: 8', stderr) |
| 59 |
| 60 def test_minus_D_cat(self): |
| 61 """Tests cat command with debug option.""" |
| 62 key_uri = self.CreateObject(contents='0123456789') |
| 63 with SetBotoConfigForTest([('Boto', 'proxy_pass', 'secret')]): |
| 64 (stdout, stderr) = self.RunGsUtil( |
| 65 ['-D', 'cat', suri(key_uri)], return_stdout=True, return_stderr=True) |
| 66 self.assertIn('You are running gsutil with debug output enabled.', stderr) |
| 67 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) |
| 68 self.assertIn('config:', stderr) |
| 69 self.assertIn("('proxy_pass', 'REDACTED')", stderr) |
| 70 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) |
| 71 self.assertIn('header: Expires: ', stderr) |
| 72 self.assertIn('header: Date: ', stderr) |
| 73 self.assertIn('header: Content-Type: application/octet-stream', stderr) |
| 74 self.assertIn('header: Content-Length: 10', stderr) |
| 75 |
| 76 if self.test_api == ApiSelector.XML: |
| 77 self.assertRegexpMatches( |
| 78 stderr, '.*HEAD /%s/%s.*Content-Length: 0.*User-Agent: .*gsutil/%s' % |
| 79 (key_uri.bucket_name, key_uri.object_name, gslib.VERSION)) |
| 80 |
| 81 self.assertIn('header: Cache-Control: private, max-age=0', |
| 82 stderr) |
| 83 self.assertIn('header: Last-Modified: ', stderr) |
| 84 self.assertIn('header: ETag: "781e5e245d69b566979b86e28d23f2c7"', stderr) |
| 85 self.assertIn('header: x-goog-generation: ', stderr) |
| 86 self.assertIn('header: x-goog-metageneration: 1', stderr) |
| 87 self.assertIn('header: x-goog-hash: crc32c=KAwGng==', stderr) |
| 88 self.assertIn('header: x-goog-hash: md5=eB5eJF1ptWaXm4bijSPyxw==', stderr) |
| 89 elif self.test_api == ApiSelector.JSON: |
| 90 self.assertRegexpMatches( |
| 91 stderr, '.*GET.*b/%s/o/%s.*user-agent:.*gsutil/%s' % |
| 92 (key_uri.bucket_name, key_uri.object_name, gslib.VERSION)) |
| 93 self.assertIn(('header: Cache-Control: no-cache, no-store, max-age=0, ' |
| 94 'must-revalidate'), stderr) |
| 95 self.assertIn("md5Hash: u'eB5eJF1ptWaXm4bijSPyxw=='", stderr) |
| 96 |
| 97 if gslib.IS_PACKAGE_INSTALL: |
| 98 self.assertIn('PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS', stdout) |
| 99 else: |
| 100 self.assertRegexpMatches(stdout, r'.*checksum: [0-9a-f]{32}.*') |
| 101 self.assertIn('gsutil version: %s' % gslib.VERSION, stdout) |
| 102 self.assertIn('boto version: ', stdout) |
| 103 self.assertIn('python version: ', stdout) |
| 104 self.assertIn('OS: ', stdout) |
| 105 self.assertIn('multiprocessing available: ', stdout) |
| 106 self.assertIn('using cloud sdk: ', stdout) |
| 107 self.assertIn('config path: ', stdout) |
| 108 self.assertIn('gsutil path: ', stdout) |
| 109 self.assertIn('compiled crcmod: ', stdout) |
| 110 self.assertIn('installed via package manager: ', stdout) |
| 111 self.assertIn('editable install: ', stdout) |
OLD | NEW |