| 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 logging command.""" |
| 16 |
| 17 from __future__ import absolute_import |
| 14 | 18 |
| 15 import gslib.tests.testcase as testcase | 19 import gslib.tests.testcase as testcase |
| 16 | 20 from gslib.tests.testcase.integration_testcase import SkipForS3 |
| 17 from gslib.tests.util import ObjectToURI as suri | 21 from gslib.tests.util import ObjectToURI as suri |
| 18 | 22 |
| 23 |
| 24 @SkipForS3('Logging command requires S3 ACL configuration on target bucket.') |
| 19 class TestLogging(testcase.GsUtilIntegrationTestCase): | 25 class TestLogging(testcase.GsUtilIntegrationTestCase): |
| 20 | 26 """Integration tests for logging command.""" |
| 21 _enable_cmd_prefix = ['logging', 'set', 'on'] | 27 |
| 22 _disable_cmd_prefix = ['logging', 'set', 'off'] | 28 _enable_log_cmd = ['logging', 'set', 'on'] |
| 23 _get_cmd_prefix = ['logging', 'get'] | 29 _disable_log_cmd = ['logging', 'set', 'off'] |
| 30 _get_log_cmd = ['logging', 'get'] |
| 24 | 31 |
| 25 def testLogging(self): | 32 def testLogging(self): |
| 33 """Tests enabling and disabling logging.""" |
| 26 bucket_uri = self.CreateBucket() | 34 bucket_uri = self.CreateBucket() |
| 27 bucket_suri = suri(bucket_uri) | 35 bucket_suri = suri(bucket_uri) |
| 28 stderr = self.RunGsUtil( | 36 stderr = self.RunGsUtil( |
| 29 self._enable_cmd_prefix + ['-b', bucket_suri, bucket_suri], | 37 self._enable_log_cmd + ['-b', bucket_suri, bucket_suri], |
| 30 return_stderr=True) | 38 return_stderr=True) |
| 31 self.assertIn('Enabling logging', stderr) | 39 self.assertIn('Enabling logging', stderr) |
| 32 | 40 |
| 33 stdout = self.RunGsUtil(self._get_cmd_prefix + [bucket_suri], | 41 stdout = self.RunGsUtil(self._get_log_cmd + [bucket_suri], |
| 34 return_stdout=True) | 42 return_stdout=True) |
| 35 self.assertIn('LogObjectPrefix', stdout) | 43 self.assertIn('LogObjectPrefix'.lower(), stdout.lower()) |
| 36 | 44 |
| 37 stderr = self.RunGsUtil(self._disable_cmd_prefix + [bucket_suri], | 45 stderr = self.RunGsUtil(self._disable_log_cmd + [bucket_suri], |
| 38 return_stderr=True) | 46 return_stderr=True) |
| 39 self.assertIn('Disabling logging', stderr) | 47 self.assertIn('Disabling logging', stderr) |
| 40 | 48 |
| 41 def testTooFewArgumentsFails(self): | 49 def testTooFewArgumentsFails(self): |
| 50 """Ensures logging commands fail with too few arguments.""" |
| 42 # No arguments for enable, but valid subcommand. | 51 # No arguments for enable, but valid subcommand. |
| 43 stderr = self.RunGsUtil(self._enable_cmd_prefix, return_stderr=True, | 52 stderr = self.RunGsUtil(self._enable_log_cmd, return_stderr=True, |
| 44 expected_status=1) | 53 expected_status=1) |
| 45 self.assertIn('command requires at least', stderr) | 54 self.assertIn('command requires at least', stderr) |
| 46 | 55 |
| 47 # No arguments for disable, but valid subcommand. | 56 # No arguments for disable, but valid subcommand. |
| 48 stderr = self.RunGsUtil(self._disable_cmd_prefix, return_stderr=True, | 57 stderr = self.RunGsUtil(self._disable_log_cmd, return_stderr=True, |
| 49 expected_status=1) | |
| 50 self.assertIn('command requires at least', stderr) | |
| 51 | |
| 52 # No arguments for get, but valid subcommand. | |
| 53 stderr = self.RunGsUtil(self._get_cmd_prefix, return_stderr=True, | |
| 54 expected_status=1) | 58 expected_status=1) |
| 55 self.assertIn('command requires at least', stderr) | 59 self.assertIn('command requires at least', stderr) |
| 56 | 60 |
| 61 # No arguments for get, but valid subcommand. |
| 62 stderr = self.RunGsUtil(self._get_log_cmd, return_stderr=True, |
| 63 expected_status=1) |
| 64 self.assertIn('command requires at least', stderr) |
| 65 |
| 57 # Neither arguments nor subcommand. | 66 # Neither arguments nor subcommand. |
| 58 stderr = self.RunGsUtil(['logging'], return_stderr=True, expected_status=1) | 67 stderr = self.RunGsUtil(['logging'], return_stderr=True, expected_status=1) |
| 59 self.assertIn('command requires at least', stderr) | 68 self.assertIn('command requires at least', stderr) |
| 60 | 69 |
| 70 |
| 61 class TestLoggingOldAlias(TestLogging): | 71 class TestLoggingOldAlias(TestLogging): |
| 62 _enable_cmd_prefix = ['enablelogging'] | 72 _enable_log_cmd = ['enablelogging'] |
| 63 _disable_cmd_prefix = ['disablelogging'] | 73 _disable_log_cmd = ['disablelogging'] |
| 64 _get_cmd_prefix = ['getlogging'] | 74 _get_log_cmd = ['getlogging'] |
| OLD | NEW |