Repository: googleapis/google-cloud-ruby (Ruby)

Issue:
google-cloud-logging: Google::Cloud::Logging::Project#resource_descriptors does not work
#### Environment details

  - OS: macOS 12.3.1
  - Ruby version: 2.7.5
  - Gem name and version: google-cloud-logging-2.2.2

#### Steps to reproduce

  1. Just call resource_descriptors on a logging object (instance of Google::Cloud::Logging::Project) as documented [here](https://cloud.google.com/ruby/docs/reference/google-cloud-logging/latest/Google-Cloud-Logging-ResourceDescriptor-List).

#### Code example

```ruby
logging = Google::Cloud::Logging.new(project_id: ENV.fetch('GOOGLE_CLOUD_LOGGING_PROJECT_ID'), credentials: Google::Cloud::Logging::Credentials.new(JSON.parse(ENV.fetch('GOOGLE_CLOUD_LOGGING_CREDENTIALS_JSON'))))
logging.resource_descriptors
```

#### Full backtrace

```
Traceback (most recent call last):
        21: from .../bin/irb:23:in `<main>'
        20: from .../bin/irb:23:in `load'
        19: from .../exe/irb:11:in `<top (required)>'
         2: from (irb):2:in `<main>'
         1: from .../gems/2.7.0/gems/google-cloud-logging-2.2.2/lib/google/cloud/logging/project.rb:551:in `resource_descriptors'
.../gems/2.7.0/gems/google-cloud-logging-2.2.2/lib/google/cloud/logging/resource_descriptor/list.rb:154:in `from_grpc': undefined method `resource_descriptors' for #<Gapic::PagedEnumerable:0x00007f933ad5b270> (NoMethodError)
```



Discussion:
@knu Thanks for reporting, I am able reproduce the issue too. We will try fixing this sooner 👍 



Patch:
diff --git a/google-cloud-logging/lib/google/cloud/logging/service.rb b/google-cloud-logging/lib/google/cloud/logging/service.rb
index 976f6002132e..0c5fd971be4d 100644
--- a/google-cloud-logging/lib/google/cloud/logging/service.rb
+++ b/google-cloud-logging/lib/google/cloud/logging/service.rb
@@ -123,7 +123,8 @@ def delete_log name
         end
 
         def list_resource_descriptors token: nil, max: nil
-          logging.list_monitored_resource_descriptors page_size: max, page_token: token
+          paged_enum = logging.list_monitored_resource_descriptors page_size: max, page_token: token
+          paged_enum.response
         end
 
         def list_sinks token: nil, max: nil


Test patch:
diff --git a/google-cloud-logging/test/google/cloud/logging/project/resource_descriptors_test.rb b/google-cloud-logging/test/google/cloud/logging/project/resource_descriptors_test.rb
index 3c469ed7b027..cd02d485ae11 100644
--- a/google-cloud-logging/test/google/cloud/logging/project/resource_descriptors_test.rb
+++ b/google-cloud-logging/test/google/cloud/logging/project/resource_descriptors_test.rb
@@ -17,10 +17,9 @@
 describe Google::Cloud::Logging::Project, :resource_descriptors, :mock_logging do
   it "lists resource descriptors" do
     num_descriptors = 3
-    list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(num_descriptors))
 
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, list_res, page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(num_descriptors), page_size: nil, page_token: nil
     logging.service.mocked_logging = mock
 
     resource_descriptors = logging.resource_descriptors
@@ -33,10 +32,9 @@
 
   it "lists resource descriptors with find_resource_descriptors alias" do
     num_descriptors = 3
-    list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(num_descriptors))
 
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, list_res, page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(num_descriptors), page_size: nil, page_token: nil
     logging.service.mocked_logging = mock
 
     resource_descriptors = logging.find_resource_descriptors
@@ -48,12 +46,9 @@
   end
 
   it "paginates resource descriptors" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(2))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: nil, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: nil, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(2), page_size: nil, page_token: "next_page_token"
     logging.service.mocked_logging = mock
 
     first_descriptors = logging.resource_descriptors
@@ -72,12 +67,9 @@
   end
 
   it "paginates resource descriptors with next? and next" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(2))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: nil, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: nil, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(2), page_size: nil, page_token: "next_page_token"
 
     logging.service.mocked_logging = mock
 
@@ -96,12 +88,9 @@
   end
 
   it "paginates resource descriptors with next? and next and max set" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(2, "second_page_token"))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: 3, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: 3, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: 3, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(2, "second_page_token"), page_size: 3, page_token: "next_page_token"
 
     logging.service.mocked_logging = mock
 
@@ -128,12 +117,9 @@
   end
 
   it "paginates resource descriptors with all" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(2))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: nil, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: nil, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(2), page_size: nil, page_token: "next_page_token"
 
     logging.service.mocked_logging = mock
 
@@ -146,12 +132,9 @@
   end
 
   it "paginates resource descriptors with all and max set" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(2))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: 3, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: 3, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: 3, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(2), page_size: 3, page_token: "next_page_token"
 
     logging.service.mocked_logging = mock
 
@@ -164,12 +147,9 @@
   end
 
   it "paginates resource descriptors with all using Enumerator" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "second_page_token"))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: nil, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: nil, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "second_page_token"), page_size: nil, page_token: "next_page_token"
 
     logging.service.mocked_logging = mock
 
@@ -182,12 +162,9 @@
   end
 
   it "paginates resource descriptors with all and request_limit set" do
-    first_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-    second_list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "second_page_token"))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, first_list_res, page_size: nil, page_token: nil
-    mock.expect :list_monitored_resource_descriptors, second_list_res, page_size: nil, page_token: "next_page_token"
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "second_page_token"), page_size: nil, page_token: "next_page_token"
 
     logging.service.mocked_logging = mock
 
@@ -200,10 +177,8 @@
   end
 
   it "paginates resource descriptors with max set" do
-    list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, list_res, page_size: 3, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: 3, page_token: nil
     logging.service.mocked_logging = mock
 
     resource_descriptors = logging.resource_descriptors max: 3
@@ -217,10 +192,8 @@
   end
 
   it "paginates resource descriptors without max set" do
-    list_res = Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(list_resource_descriptors_hash(3, "next_page_token"))
-
     mock = Minitest::Mock.new
-    mock.expect :list_monitored_resource_descriptors, list_res, page_size: nil, page_token: nil
+    mock.expect :list_monitored_resource_descriptors, list_resource_descriptors_hash(3, "next_page_token"), page_size: nil, page_token: nil
     logging.service.mocked_logging = mock
 
     resource_descriptors = logging.resource_descriptors
@@ -234,9 +207,15 @@
   end
 
   def list_resource_descriptors_hash count = 2, token = nil
-    {
+    response = {
       resource_descriptors: count.times.map { random_resource_descriptor_hash },
       next_page_token: token
     }.delete_if { |_, v| v.nil? }
+    ::Gapic::PagedEnumerable.new nil, 
+                                 :list_monitored_resource_descriptors, 
+                                 Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsRequest.new, 
+                                 Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse.new(response), 
+                                 nil, 
+                                 nil
   end
 end