| OLD | NEW |
| 1 # -*- coding: utf-8 -*- |
| 1 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 2 # | 3 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # 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 not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 6 # | 7 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 9 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 14 # limitations under the License. |
| 15 """Integration tests for gsutil -D option.""" |
| 14 | 16 |
| 15 import boto | 17 from __future__ import absolute_import |
| 18 |
| 16 import gslib | 19 import gslib |
| 20 from gslib.cs_api_map import ApiSelector |
| 17 import gslib.tests.testcase as testcase | 21 import gslib.tests.testcase as testcase |
| 22 from gslib.tests.testcase.integration_testcase import SkipForS3 |
| 18 from gslib.tests.util import ObjectToURI as suri | 23 from gslib.tests.util import ObjectToURI as suri |
| 24 from gslib.tests.util import SetBotoConfigForTest |
| 25 from gslib.util import ONE_KB |
| 19 | 26 |
| 20 | 27 |
| 21 class TestCat(testcase.GsUtilIntegrationTestCase): | 28 @SkipForS3('-D output is implementation-specific.') |
| 29 class TestDOption(testcase.GsUtilIntegrationTestCase): |
| 22 """Integration tests for gsutil -D option.""" | 30 """Integration tests for gsutil -D option.""" |
| 23 | 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_KB))]): |
| 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 |
| 24 def test_minus_D_cat(self): | 60 def test_minus_D_cat(self): |
| 61 """Tests cat command with debug option.""" |
| 25 key_uri = self.CreateObject(contents='0123456789') | 62 key_uri = self.CreateObject(contents='0123456789') |
| 26 (stdout, stderr) = self.RunGsUtil(['-D', 'cat', suri(key_uri)], | 63 with SetBotoConfigForTest([('Boto', 'proxy_pass', 'secret')]): |
| 27 return_stdout=True, return_stderr=True) | 64 (stdout, stderr) = self.RunGsUtil( |
| 65 ['-D', 'cat', suri(key_uri)], return_stdout=True, return_stderr=True) |
| 28 self.assertIn('You are running gsutil with debug output enabled.', stderr) | 66 self.assertIn('You are running gsutil with debug output enabled.', stderr) |
| 29 self.assertIn('config: [', stderr) | 67 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) |
| 30 self.assertRegexpMatches( | 68 self.assertIn('config:', stderr) |
| 31 stderr, '.*HEAD /%s/%s.*Content-Length: 0.*User-Agent: .*gsutil/%s' % | 69 self.assertIn("('proxy_pass', 'REDACTED')", stderr) |
| 32 (key_uri.bucket_name, key_uri.object_name, gslib.VERSION)) | |
| 33 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) | 70 self.assertIn("reply: 'HTTP/1.1 200 OK", stderr) |
| 34 self.assertIn('header: Expires: ', stderr) | 71 self.assertIn('header: Expires: ', stderr) |
| 35 self.assertIn('header: Date: ', stderr) | 72 self.assertIn('header: Date: ', stderr) |
| 36 self.assertIn('header: Cache-Control: private, max-age=0', | |
| 37 stderr) | |
| 38 self.assertIn('header: Last-Modified: ', stderr) | |
| 39 self.assertIn('header: ETag: "781e5e245d69b566979b86e28d23f2c7"', stderr) | |
| 40 self.assertIn('header: x-goog-generation: ', stderr) | |
| 41 self.assertIn('header: x-goog-metageneration: 1', stderr) | |
| 42 self.assertIn('header: Content-Type: application/octet-stream', stderr) | 73 self.assertIn('header: Content-Type: application/octet-stream', stderr) |
| 43 self.assertIn('header: Content-Length: 10', stderr) | 74 self.assertIn('header: Content-Length: 10', stderr) |
| 44 self.assertIn('header: x-goog-hash: crc32c=KAwGng==', stderr) | 75 |
| 45 self.assertIn('header: x-goog-hash: md5=eB5eJF1ptWaXm4bijSPyxw==', stderr) | 76 if self.test_api == ApiSelector.XML: |
| 46 self.assertIn('gsutil version %s' % gslib.VERSION, stdout) | 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 |
| 47 if gslib.IS_PACKAGE_INSTALL: | 97 if gslib.IS_PACKAGE_INSTALL: |
| 48 self.assertIn('PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS', stdout) | 98 self.assertIn('PACKAGED_GSUTIL_INSTALLS_DO_NOT_HAVE_CHECKSUMS', stdout) |
| 49 else: | 99 else: |
| 50 self.assertRegexpMatches(stdout, r'.*checksum [0-9a-f]{32}.*') | 100 self.assertRegexpMatches(stdout, r'.*checksum: [0-9a-f]{32}.*') |
| 51 self.assertIn('boto version ', stdout) | 101 self.assertIn('gsutil version: %s' % gslib.VERSION, stdout) |
| 52 self.assertIn('python 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) |
| 53 self.assertIn('config path: ', stdout) | 107 self.assertIn('config path: ', stdout) |
| 54 self.assertIn('gsutil path: ', stdout) | 108 self.assertIn('gsutil path: ', stdout) |
| 55 self.assertIn('compiled crcmod: ', stdout) | 109 self.assertIn('compiled crcmod: ', stdout) |
| 56 self.assertIn('installed via package manager: ', stdout) | 110 self.assertIn('installed via package manager: ', stdout) |
| 57 self.assertIn('editable install: ', stdout) | 111 self.assertIn('editable install: ', stdout) |
| OLD | NEW |