From f9773372bf24ae9ffcf86e689ca94785bb8e35fd Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Tue, 17 Sep 2024 10:27:20 +0000 Subject: [PATCH 01/12] adding sample --- .../acceptance/storage/bucket_test.rb | 19 ++++++++++ .../samples/acceptance/buckets_test.rb | 21 +++++++++++ .../storage_get_bucket_class_and_location.rb | 37 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 google-cloud-storage/samples/storage_get_bucket_class_and_location.rb diff --git a/google-cloud-storage/acceptance/storage/bucket_test.rb b/google-cloud-storage/acceptance/storage/bucket_test.rb index ea99e617db26..bb301ec1db73 100644 --- a/google-cloud-storage/acceptance/storage/bucket_test.rb +++ b/google-cloud-storage/acceptance/storage/bucket_test.rb @@ -315,6 +315,25 @@ safe_gcs_execute { one_off_bucket.delete } _(storage.bucket(one_off_bucket_name)).must_be :nil? end + describe "get_bucket_class_and_location" do + bucket_name = "my-simple-buckrt" + location = "US" + storage_class = "COLDLINE" + + it "get_bucket_class_and_location" do + + storage.create_bucket bucket_name, + location: location, + storage_class: storage_class + + + assert_output("Bucket #{bucket_name} default storage class is #{storage_class}, and the location is #{location}") do + get_bucket_class_and_location bucket_name: bucket_name + end + + + end + end describe "anonymous project" do it "raises when creating a bucket without authentication" do diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 23513062d946..2028959e04e8 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -34,6 +34,7 @@ require_relative "../storage_enable_requester_pays" require_relative "../storage_enable_uniform_bucket_level_access" require_relative "../storage_enable_versioning" +require_relative "../storage_get_bucket_class_and_location" require_relative "../storage_get_bucket_metadata" require_relative "../storage_get_default_event_based_hold" require_relative "../storage_get_public_access_prevention" @@ -349,6 +350,26 @@ end end + describe "get_bucket_class_and_location" do + bucket_name = "my-simple-buckrt" + location = "US" + storage_class = "COLDLINE" + + it "get_bucket_class_and_location" do + + storage.create_bucket bucket_name, + location: location, + storage_class: storage_class + + + assert_output("Bucket #{bucket_name} default storage class is #{storage_class}, and the location is #{location}") do + get_bucket_class_and_location bucket_name: bucket_name + end + + + end + end + describe "labels" do it "add_bucket_label, remove_bucket_label" do # add_bucket_label diff --git a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb new file mode 100644 index 000000000000..ac2f1cd48b5b --- /dev/null +++ b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb @@ -0,0 +1,37 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_get_bucket_class_and_location] + +def get_bucket_class_and_location bucket_name: + # The ID of your GCS bucket + # bucket_name = "your-unique-bucket-name" + require "google/cloud/storage" + + # Initialize Google Cloud Storage client + storage = Google::Cloud::Storage.new + + # Fetch bucket metadata + bucket = storage.bucket bucket_name + + # Handle the case where the bucket is not found + raise "Bucket not found: #{bucket_name}" if bucket.nil? + + # Output the bucket's default storage class and location + puts "Bucket #{bucket.name} default storage class is #{bucket.storage_class}, and the location is #{bucket.location}" +end +# [END storage_get_bucket_class_and_location] + + +get_bucket_class_and_location bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ From 5b09cd3ed6b30f9bcad59a0f2d7f29bac615e91b Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 18 Sep 2024 04:21:43 +0000 Subject: [PATCH 02/12] adding test cases --- .../acceptance/storage/bucket_test.rb | 12 ++++-------- .../samples/acceptance/buckets_test.rb | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/google-cloud-storage/acceptance/storage/bucket_test.rb b/google-cloud-storage/acceptance/storage/bucket_test.rb index bb301ec1db73..356de724be6f 100644 --- a/google-cloud-storage/acceptance/storage/bucket_test.rb +++ b/google-cloud-storage/acceptance/storage/bucket_test.rb @@ -316,22 +316,18 @@ _(storage.bucket(one_off_bucket_name)).must_be :nil? end describe "get_bucket_class_and_location" do - bucket_name = "my-simple-buckrt" + bucket_name = "my-simple-bucket" location = "US" storage_class = "COLDLINE" it "get_bucket_class_and_location" do - storage.create_bucket bucket_name, - location: location, - storage_class: storage_class - - + storage.create_bucket bucket_name, + location: location, + storage_class: storage_class assert_output("Bucket #{bucket_name} default storage class is #{storage_class}, and the location is #{location}") do get_bucket_class_and_location bucket_name: bucket_name end - - end end diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 2028959e04e8..3cf20c387629 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -350,23 +350,19 @@ end end - describe "get_bucket_class_and_location" do - bucket_name = "my-simple-buckrt" + describe "get_bucket_class_and_location" do + bucket_name = "my-simple-bucket" location = "US" storage_class = "COLDLINE" it "get_bucket_class_and_location" do - storage.create_bucket bucket_name, - location: location, - storage_class: storage_class + location: location, + storage_class: storage_class - assert_output("Bucket #{bucket_name} default storage class is #{storage_class}, and the location is #{location}") do get_bucket_class_and_location bucket_name: bucket_name end - - end end From 901da5f25b5ffaa5b5cb1c92180f576ceb1d00d2 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 18 Sep 2024 04:25:14 +0000 Subject: [PATCH 03/12] refacroting --- .../acceptance/storage/bucket_test.rb | 10 ++++++---- .../samples/acceptance/buckets_test.rb | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/google-cloud-storage/acceptance/storage/bucket_test.rb b/google-cloud-storage/acceptance/storage/bucket_test.rb index 356de724be6f..9698d7ae0fad 100644 --- a/google-cloud-storage/acceptance/storage/bucket_test.rb +++ b/google-cloud-storage/acceptance/storage/bucket_test.rb @@ -315,21 +315,23 @@ safe_gcs_execute { one_off_bucket.delete } _(storage.bucket(one_off_bucket_name)).must_be :nil? end + describe "get_bucket_class_and_location" do - bucket_name = "my-simple-bucket" + bucket_name = "my-simple-bucket" location = "US" storage_class = "COLDLINE" it "get_bucket_class_and_location" do - storage.create_bucket bucket_name, location: location, storage_class: storage_class - assert_output("Bucket #{bucket_name} default storage class is #{storage_class}, and the location is #{location}") do + expected_output = "Bucket #{bucket_name} default storage class is " \ + "#{storage_class}, and the location is #{location}" + assert_output expected_output do get_bucket_class_and_location bucket_name: bucket_name end end - end + end describe "anonymous project" do it "raises when creating a bucket without authentication" do diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 3cf20c387629..58aea4f80e5c 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -351,20 +351,21 @@ end describe "get_bucket_class_and_location" do - bucket_name = "my-simple-bucket" + bucket_name = "my-simple-bucket" location = "US" storage_class = "COLDLINE" it "get_bucket_class_and_location" do - storage.create_bucket bucket_name, + storage.create_bucket bucket_name, location: location, storage_class: storage_class - - assert_output("Bucket #{bucket_name} default storage class is #{storage_class}, and the location is #{location}") do + expected_output = "Bucket #{bucket_name} default storage class is " \ + "#{storage_class}, and the location is #{location}" + assert_output expected_output do get_bucket_class_and_location bucket_name: bucket_name end end - end + end describe "labels" do it "add_bucket_label, remove_bucket_label" do From 1ea4bad52081f5c3d4f029ef02f460fac40cb928 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 18 Sep 2024 05:33:09 +0000 Subject: [PATCH 04/12] removing unwanted test --- .../acceptance/storage/bucket_test.rb | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/google-cloud-storage/acceptance/storage/bucket_test.rb b/google-cloud-storage/acceptance/storage/bucket_test.rb index 9698d7ae0fad..ea99e617db26 100644 --- a/google-cloud-storage/acceptance/storage/bucket_test.rb +++ b/google-cloud-storage/acceptance/storage/bucket_test.rb @@ -315,23 +315,6 @@ safe_gcs_execute { one_off_bucket.delete } _(storage.bucket(one_off_bucket_name)).must_be :nil? end - - describe "get_bucket_class_and_location" do - bucket_name = "my-simple-bucket" - location = "US" - storage_class = "COLDLINE" - - it "get_bucket_class_and_location" do - storage.create_bucket bucket_name, - location: location, - storage_class: storage_class - expected_output = "Bucket #{bucket_name} default storage class is " \ - "#{storage_class}, and the location is #{location}" - assert_output expected_output do - get_bucket_class_and_location bucket_name: bucket_name - end - end - end describe "anonymous project" do it "raises when creating a bucket without authentication" do From fcef8a415cbb3aafb58400f3e466d7320b5567c5 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Wed, 18 Sep 2024 06:42:13 +0000 Subject: [PATCH 05/12] fixing test --- google-cloud-storage/samples/acceptance/buckets_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 58aea4f80e5c..696342c02841 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -351,12 +351,12 @@ end describe "get_bucket_class_and_location" do - bucket_name = "my-simple-bucket" + bucket_name = "my-simple-storage-bucket" location = "US" storage_class = "COLDLINE" it "get_bucket_class_and_location" do - storage.create_bucket bucket_name, + storage_client.create_bucket bucket_name, location: location, storage_class: storage_class expected_output = "Bucket #{bucket_name} default storage class is " \ From 741a91ab940c03f17411a8e050033032535535f7 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Sep 2024 07:00:56 +0000 Subject: [PATCH 06/12] simple fixes --- google-cloud-storage/samples/acceptance/buckets_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 696342c02841..4a20c97a7081 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -1,4 +1,4 @@ -# Copyright 2020 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -350,7 +350,7 @@ end end - describe "get_bucket_class_and_location" do + describe "Get Bucket Class And Location data" do bucket_name = "my-simple-storage-bucket" location = "US" storage_class = "COLDLINE" From e3eb04f87e2457d8e2a07789c1406af622309198 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Sep 2024 07:03:09 +0000 Subject: [PATCH 07/12] simple fixes --- .../samples/storage_get_bucket_class_and_location.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb index ac2f1cd48b5b..dbb88203baa6 100644 --- a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb +++ b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb @@ -33,5 +33,4 @@ def get_bucket_class_and_location bucket_name: end # [END storage_get_bucket_class_and_location] - get_bucket_class_and_location bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ From 880b7c4a4c275970972fdbbdc079d804300cb0c7 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Sep 2024 07:03:58 +0000 Subject: [PATCH 08/12] simple fixes --- .../samples/storage_get_bucket_class_and_location.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb index dbb88203baa6..8bd57e468fd1 100644 --- a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb +++ b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb @@ -1,4 +1,4 @@ -# Copyright 2020 Google LLC +# Copyright 2024 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 410c593259fe2da984dae70cb9614fd33df3f357 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Sep 2024 07:44:52 +0000 Subject: [PATCH 09/12] simple fix --- google-cloud-storage/samples/acceptance/buckets_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 4a20c97a7081..f43b98755329 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -350,7 +350,7 @@ end end - describe "Get Bucket Class And Location data" do + describe "get bucket class and location data" do bucket_name = "my-simple-storage-bucket" location = "US" storage_class = "COLDLINE" From 028cc4aa468a5f58f0a501fae8f03bf17db4a551 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Sep 2024 12:53:35 +0000 Subject: [PATCH 10/12] fixing allignment --- google-cloud-storage/samples/acceptance/buckets_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index f43b98755329..091d1508f977 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -357,10 +357,10 @@ it "get_bucket_class_and_location" do storage_client.create_bucket bucket_name, - location: location, - storage_class: storage_class + location: location, + storage_class: storage_class expected_output = "Bucket #{bucket_name} default storage class is " \ - "#{storage_class}, and the location is #{location}" + "#{storage_class}, and the location is #{location}" assert_output expected_output do get_bucket_class_and_location bucket_name: bucket_name end From 275ff62ab4c69d418e32532481a9ec8ff03e5e12 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 19 Sep 2024 14:14:47 +0000 Subject: [PATCH 11/12] fixing failing test --- google-cloud-storage/samples/acceptance/buckets_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index 091d1508f977..a605dab9409f 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -351,7 +351,7 @@ end describe "get bucket class and location data" do - bucket_name = "my-simple-storage-bucket" + bucket_name = random_bucket_name location = "US" storage_class = "COLDLINE" @@ -360,7 +360,7 @@ location: location, storage_class: storage_class expected_output = "Bucket #{bucket_name} default storage class is " \ - "#{storage_class}, and the location is #{location}" + "#{storage_class}, and the location is #{location}\n" assert_output expected_output do get_bucket_class_and_location bucket_name: bucket_name end From 750104c6dd719e8e04da139ca0c7ad86bcd2ea06 Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Fri, 20 Sep 2024 09:28:05 +0000 Subject: [PATCH 12/12] changing wordings of sample output string --- google-cloud-storage/samples/acceptance/buckets_test.rb | 4 ++-- .../samples/storage_get_bucket_class_and_location.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/google-cloud-storage/samples/acceptance/buckets_test.rb b/google-cloud-storage/samples/acceptance/buckets_test.rb index a605dab9409f..f3d0e42f8ba1 100644 --- a/google-cloud-storage/samples/acceptance/buckets_test.rb +++ b/google-cloud-storage/samples/acceptance/buckets_test.rb @@ -1,4 +1,4 @@ -# Copyright 2024 Google LLC +# Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -359,7 +359,7 @@ storage_client.create_bucket bucket_name, location: location, storage_class: storage_class - expected_output = "Bucket #{bucket_name} default storage class is " \ + expected_output = "Bucket #{bucket_name} storage class is " \ "#{storage_class}, and the location is #{location}\n" assert_output expected_output do get_bucket_class_and_location bucket_name: bucket_name diff --git a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb index 8bd57e468fd1..9eb27c084096 100644 --- a/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb +++ b/google-cloud-storage/samples/storage_get_bucket_class_and_location.rb @@ -28,8 +28,8 @@ def get_bucket_class_and_location bucket_name: # Handle the case where the bucket is not found raise "Bucket not found: #{bucket_name}" if bucket.nil? - # Output the bucket's default storage class and location - puts "Bucket #{bucket.name} default storage class is #{bucket.storage_class}, and the location is #{bucket.location}" + # Output the bucket's storage class and location + puts "Bucket #{bucket.name} storage class is #{bucket.storage_class}, and the location is #{bucket.location}" end # [END storage_get_bucket_class_and_location]