1 # -*- coding: utf-8 -*-
2 # Copyright 2013 Google Inc. All Rights Reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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."""
17 from __future__
import absolute_import
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
24 @SkipForS3('Logging command requires S3 ACL configuration on target bucket.')
25 class TestLogging(testcase
.GsUtilIntegrationTestCase
):
26 """Integration tests for logging command."""
28 _enable_log_cmd
= ['logging', 'set', 'on']
29 _disable_log_cmd
= ['logging', 'set', 'off']
30 _get_log_cmd
= ['logging', 'get']
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
],
39 self
.assertIn('Enabling logging', stderr
)
41 stdout
= self
.RunGsUtil(self
._get
_log
_cmd
+ [bucket_suri
],
43 self
.assertIn('LogObjectPrefix'.lower(), stdout
.lower())
45 stderr
= self
.RunGsUtil(self
._disable
_log
_cmd
+ [bucket_suri
],
47 self
.assertIn('Disabling logging', stderr
)
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,
54 self
.assertIn('command requires at least', stderr
)
56 # No arguments for disable, but valid subcommand.
57 stderr
= self
.RunGsUtil(self
._disable
_log
_cmd
, return_stderr
=True,
59 self
.assertIn('command requires at least', stderr
)
61 # No arguments for get, but valid subcommand.
62 stderr
= self
.RunGsUtil(self
._get
_log
_cmd
, return_stderr
=True,
64 self
.assertIn('command requires at least', stderr
)
66 # Neither arguments nor subcommand.
67 stderr
= self
.RunGsUtil(['logging'], return_stderr
=True, expected_status
=1)
68 self
.assertIn('command requires at least', stderr
)
71 class TestLoggingOldAlias(TestLogging
):
72 _enable_log_cmd
= ['enablelogging']
73 _disable_log_cmd
= ['disablelogging']
74 _get_log_cmd
= ['getlogging']