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