1 # -*- coding: utf-8 -*- 2 # Copyright 2014 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 rb command.""" 16 17 from __future__ import absolute_import 18 19 import gslib.tests.testcase as testcase 20 from gslib.tests.util import ObjectToURI as suri 21 22 23 class TestRb(testcase.GsUtilIntegrationTestCase): 24 """Integration tests for rb command.""" 25 26 def test_rb_bucket_works(self): 27 bucket_uri = self.CreateBucket() 28 self.RunGsUtil(['rb', suri(bucket_uri)]) 29 stderr = self.RunGsUtil( 30 ['ls', '-Lb', 'gs://%s' % self.nonexistent_bucket_name], 31 return_stderr=True, expected_status=1) 32 self.assertIn('404', stderr) 33 34 def test_rb_bucket_not_empty(self): 35 bucket_uri = self.CreateBucket(test_objects=1) 36 stderr = self.RunGsUtil(['rb', suri(bucket_uri)], expected_status=1, 37 return_stderr=True) 38 self.assertIn('BucketNotEmpty', stderr) 39 40 def test_rb_versioned_bucket_not_empty(self): 41 bucket_uri = self.CreateVersionedBucket(test_objects=1) 42 stderr = self.RunGsUtil(['rb', suri(bucket_uri)], expected_status=1, 43 return_stderr=True) 44 self.assertIn('Bucket is not empty. Note: this is a versioned bucket', 45 stderr) 46 47 def test_rb_nonexistent_bucket(self): 48 stderr = self.RunGsUtil(['rb', 'gs://%s' % self.nonexistent_bucket_name], 49 return_stderr=True, expected_status=1) 50 self.assertIn('does not exist.', stderr) 51 52 def test_rb_minus_f(self): 53 bucket_uri = self.CreateBucket() 54 stderr = self.RunGsUtil([ 55 'rb', '-f', 'gs://%s' % self.nonexistent_bucket_name, 56 suri(bucket_uri)], return_stderr=True, expected_status=1) 57 # There should be no error output, and existing bucket named after 58 # non-existent bucket should be gone. 59 self.assertNotIn('bucket does not exist.', stderr) 60 stderr = self.RunGsUtil( 61 ['ls', '-Lb', suri(bucket_uri)], return_stderr=True, expected_status=1) 62 self.assertIn('404', stderr) 63