From 6bffe0b7a9d379f1596678753d999845c5ed8757 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Mon, 22 Jul 2024 22:01:26 +0000 Subject: [PATCH] chore(bigtable): fix conformance tests --- google-cloud-bigtable/.rubocop.yml | 1 + google-cloud-bigtable/.toys.rb | 49 ++++++++++++++++++- .../cloud/conformance/bigtable/v2/tests_pb.rb | 32 ++++-------- google-cloud-bigtable/test/test_proxy/Gemfile | 8 +-- .../bigtable/testproxy}/test_proxy.proto | 0 .../bigtable/testproxy/test_proxy_pb.rb | 27 +--------- .../testproxy/test_proxy_services_pb.rb | 0 .../test/test_proxy/test_proxy.rb | 8 +-- 8 files changed, 69 insertions(+), 56 deletions(-) rename google-cloud-bigtable/test/test_proxy/proto/{ => google/bigtable/testproxy}/test_proxy.proto (100%) rename google-cloud-bigtable/test/test_proxy/{lib => proto}/google/bigtable/testproxy/test_proxy_pb.rb (87%) rename google-cloud-bigtable/test/test_proxy/{lib => proto}/google/bigtable/testproxy/test_proxy_services_pb.rb (100%) diff --git a/google-cloud-bigtable/.rubocop.yml b/google-cloud-bigtable/.rubocop.yml index 368b0e377df4..96286b7dd5e7 100644 --- a/google-cloud-bigtable/.rubocop.yml +++ b/google-cloud-bigtable/.rubocop.yml @@ -20,6 +20,7 @@ Metrics/BlockLength: - "google-cloud-bigtable.gemspec" - "Rakefile" - "lib/google-cloud-bigtable.rb" + - ".toys.rb" Metrics/ClassLength: Max: 400 Metrics/PerceivedComplexity: diff --git a/google-cloud-bigtable/.toys.rb b/google-cloud-bigtable/.toys.rb index da8af3ecccb7..b618f91b09ae 100644 --- a/google-cloud-bigtable/.toys.rb +++ b/google-cloud-bigtable/.toys.rb @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -toys_version! ">= 0.15.3" +toys_version! ">= 0.15.6" if ENV["RUBY_COMMON_TOOLS"] common_tools_dir = File.expand_path ENV["RUBY_COMMON_TOOLS"] @@ -24,3 +24,50 @@ path: "toys/gapic", update: true end + +tool "conformance" do + tool "gen-protos" do + include :exec, e: true + include :gems + include :git_cache + + def run + setup + generate_conformance + generate_test_proxy + end + + def setup + gem "grpc-tools", "~> 1.65" + @googleapis_dir = git_cache.get "https://github.com/googleapis/googleapis.git", update: true + Dir.chdir context_directory + end + + def generate_conformance + Dir.chdir "conformance/v2/proto" do + cmd = [ + "grpc_tools_ruby_protoc", + "--ruby_out", ".", + "-I", ".", + "-I", @googleapis_dir, + "google/cloud/conformance/bigtable/v2/tests.proto" + ] + exec cmd + end + end + + def generate_test_proxy + Dir.chdir "test/test_proxy/proto" do + cmd = [ + "grpc_tools_ruby_protoc", + "--ruby_out", ".", + "--grpc_out", ".", + "-I", ".", + "-I", @googleapis_dir, + "google/bigtable/testproxy/test_proxy.proto" + ] + exec cmd + end + end + end +end diff --git a/google-cloud-bigtable/conformance/v2/proto/google/cloud/conformance/bigtable/v2/tests_pb.rb b/google-cloud-bigtable/conformance/v2/proto/google/cloud/conformance/bigtable/v2/tests_pb.rb index 812c48c9284f..331e4be192f7 100644 --- a/google-cloud-bigtable/conformance/v2/proto/google/cloud/conformance/bigtable/v2/tests_pb.rb +++ b/google-cloud-bigtable/conformance/v2/proto/google/cloud/conformance/bigtable/v2/tests_pb.rb @@ -1,37 +1,25 @@ +# frozen_string_literal: true # Generated by the protocol buffer compiler. DO NOT EDIT! # source: google/cloud/conformance/bigtable/v2/tests.proto require 'google/protobuf' require 'google/bigtable/v2/bigtable_pb' -Google::Protobuf::DescriptorPool.generated_pool.build do - add_message "google.cloud.conformance.bigtable.v2.TestFile" do - repeated :read_rows_tests, :message, 1, "google.cloud.conformance.bigtable.v2.ReadRowsTest" - end - add_message "google.cloud.conformance.bigtable.v2.ReadRowsTest" do - optional :description, :string, 1 - repeated :chunks, :message, 2, "google.bigtable.v2.ReadRowsResponse.CellChunk" - repeated :results, :message, 3, "google.cloud.conformance.bigtable.v2.ReadRowsTest.Result" - end - add_message "google.cloud.conformance.bigtable.v2.ReadRowsTest.Result" do - optional :row_key, :string, 1 - optional :family_name, :string, 2 - optional :qualifier, :string, 3 - optional :timestamp_micros, :int64, 4 - optional :value, :string, 5 - optional :label, :string, 6 - optional :error, :bool, 7 - end -end + + +descriptor_data = "\n0google/cloud/conformance/bigtable/v2/tests.proto\x12$google.cloud.conformance.bigtable.v2\x1a!google/bigtable/v2/bigtable.proto\"W\n\x08TestFile\x12K\n\x0fread_rows_tests\x18\x01 \x03(\x0b\x32\x32.google.cloud.conformance.bigtable.v2.ReadRowsTest\"\xba\x02\n\x0cReadRowsTest\x12\x13\n\x0b\x64\x65scription\x18\x01 \x01(\t\x12>\n\x06\x63hunks\x18\x02 \x03(\x0b\x32..google.bigtable.v2.ReadRowsResponse.CellChunk\x12J\n\x07results\x18\x03 \x03(\x0b\x32\x39.google.cloud.conformance.bigtable.v2.ReadRowsTest.Result\x1a\x88\x01\n\x06Result\x12\x0f\n\x07row_key\x18\x01 \x01(\t\x12\x13\n\x0b\x66\x61mily_name\x18\x02 \x01(\t\x12\x11\n\tqualifier\x18\x03 \x01(\t\x12\x18\n\x10timestamp_micros\x18\x04 \x01(\x03\x12\r\n\x05value\x18\x05 \x01(\t\x12\r\n\x05label\x18\x06 \x01(\t\x12\r\n\x05\x65rror\x18\x07 \x01(\x08\x42g\n(com.google.cloud.conformance.bigtable.v2B\x0eTestDefinition\xaa\x02*Google.Cloud.Bigtable.V2.Tests.Conformanceb\x06proto3" + +pool = Google::Protobuf::DescriptorPool.generated_pool +pool.add_serialized_file(descriptor_data) module Google module Cloud module Conformance module Bigtable module V2 - TestFile = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.conformance.bigtable.v2.TestFile").msgclass - ReadRowsTest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.conformance.bigtable.v2.ReadRowsTest").msgclass - ReadRowsTest::Result = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.conformance.bigtable.v2.ReadRowsTest.Result").msgclass + TestFile = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.conformance.bigtable.v2.TestFile").msgclass + ReadRowsTest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.conformance.bigtable.v2.ReadRowsTest").msgclass + ReadRowsTest::Result = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.conformance.bigtable.v2.ReadRowsTest.Result").msgclass end end end diff --git a/google-cloud-bigtable/test/test_proxy/Gemfile b/google-cloud-bigtable/test/test_proxy/Gemfile index c91da1ac3a62..af0c629fcd1e 100644 --- a/google-cloud-bigtable/test/test_proxy/Gemfile +++ b/google-cloud-bigtable/test/test_proxy/Gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gem "google-cloud-bigtable", path: "../../" -gem "grpc", "~> 1.62" -gem "grpc-tools", "~> 1.62" -gem "googleapis-common-protos", "~> 1.5" -gem "googleapis-common-protos-types", "~> 1.14" +gem "grpc", "~> 1.65" +gem "grpc-tools", "~> 1.65" +gem "googleapis-common-protos", "~> 1.6" +gem "googleapis-common-protos-types", "~> 1.15" diff --git a/google-cloud-bigtable/test/test_proxy/proto/test_proxy.proto b/google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy.proto similarity index 100% rename from google-cloud-bigtable/test/test_proxy/proto/test_proxy.proto rename to google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy.proto diff --git a/google-cloud-bigtable/test/test_proxy/lib/google/bigtable/testproxy/test_proxy_pb.rb b/google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy_pb.rb similarity index 87% rename from google-cloud-bigtable/test/test_proxy/lib/google/bigtable/testproxy/test_proxy_pb.rb rename to google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy_pb.rb index f64017d6161f..975b815befcc 100644 --- a/google-cloud-bigtable/test/test_proxy/lib/google/bigtable/testproxy/test_proxy_pb.rb +++ b/google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy_pb.rb @@ -14,32 +14,7 @@ descriptor_data = "\n*google/bigtable/testproxy/test_proxy.proto\x12\x19google.bigtable.testproxy\x1a\x17google/api/client.proto\x1a!google/bigtable/v2/bigtable.proto\x1a\x1dgoogle/bigtable/v2/data.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x17google/rpc/status.proto\"\x8b\x02\n\x13\x43reateClientRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x61ta_target\x18\x02 \x01(\t\x12\x12\n\nproject_id\x18\x03 \x01(\t\x12\x13\n\x0binstance_id\x18\x04 \x01(\t\x12\x16\n\x0e\x61pp_profile_id\x18\x05 \x01(\t\x12\x38\n\x15per_operation_timeout\x18\x06 \x01(\x0b\x32\x19.google.protobuf.Duration\x12Q\n\x17optional_feature_config\x18\x07 \x01(\x0e\x32\x30.google.bigtable.testproxy.OptionalFeatureConfig\"\x16\n\x14\x43reateClientResponse\"\'\n\x12\x43loseClientRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\"\x15\n\x13\x43loseClientResponse\"(\n\x13RemoveClientRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\"\x16\n\x14RemoveClientResponse\"w\n\x0eReadRowRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x12\n\ntable_name\x18\x04 \x01(\t\x12\x0f\n\x07row_key\x18\x02 \x01(\t\x12-\n\x06\x66ilter\x18\x03 \x01(\x0b\x32\x1d.google.bigtable.v2.RowFilter\"U\n\tRowResult\x12\"\n\x06status\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12$\n\x03row\x18\x02 \x01(\x0b\x32\x17.google.bigtable.v2.Row\"u\n\x0fReadRowsRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x34\n\x07request\x18\x02 \x01(\x0b\x32#.google.bigtable.v2.ReadRowsRequest\x12\x19\n\x11\x63\x61ncel_after_rows\x18\x03 \x01(\x05\"W\n\nRowsResult\x12\"\n\x06status\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12%\n\x04rows\x18\x02 \x03(\x0b\x32\x17.google.bigtable.v2.Row\"\\\n\x10MutateRowRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x35\n\x07request\x18\x02 \x01(\x0b\x32$.google.bigtable.v2.MutateRowRequest\"5\n\x0fMutateRowResult\x12\"\n\x06status\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\"^\n\x11MutateRowsRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x36\n\x07request\x18\x02 \x01(\x0b\x32%.google.bigtable.v2.MutateRowsRequest\"u\n\x10MutateRowsResult\x12\"\n\x06status\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12=\n\x07\x65ntries\x18\x02 \x03(\x0b\x32,.google.bigtable.v2.MutateRowsResponse.Entry\"l\n\x18\x43heckAndMutateRowRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12=\n\x07request\x18\x02 \x01(\x0b\x32,.google.bigtable.v2.CheckAndMutateRowRequest\"|\n\x17\x43heckAndMutateRowResult\x12\"\n\x06status\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12=\n\x06result\x18\x02 \x01(\x0b\x32-.google.bigtable.v2.CheckAndMutateRowResponse\"d\n\x14SampleRowKeysRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12\x39\n\x07request\x18\x02 \x01(\x0b\x32(.google.bigtable.v2.SampleRowKeysRequest\"u\n\x13SampleRowKeysResult\x12\"\n\x06status\x18\x01 \x01(\x0b\x32\x12.google.rpc.Status\x12:\n\x07samples\x18\x02 \x03(\x0b\x32).google.bigtable.v2.SampleRowKeysResponse\"n\n\x19ReadModifyWriteRowRequest\x12\x11\n\tclient_id\x18\x01 \x01(\t\x12>\n\x07request\x18\x02 \x01(\x0b\x32-.google.bigtable.v2.ReadModifyWriteRowRequest*d\n\x15OptionalFeatureConfig\x12#\n\x1fOPTIONAL_FEATURE_CONFIG_DEFAULT\x10\x00\x12&\n\"OPTIONAL_FEATURE_CONFIG_ENABLE_ALL\x10\x01\x32\xa4\t\n\x18\x43loudBigtableV2TestProxy\x12q\n\x0c\x43reateClient\x12..google.bigtable.testproxy.CreateClientRequest\x1a/.google.bigtable.testproxy.CreateClientResponse\"\x00\x12n\n\x0b\x43loseClient\x12-.google.bigtable.testproxy.CloseClientRequest\x1a..google.bigtable.testproxy.CloseClientResponse\"\x00\x12q\n\x0cRemoveClient\x12..google.bigtable.testproxy.RemoveClientRequest\x1a/.google.bigtable.testproxy.RemoveClientResponse\"\x00\x12\\\n\x07ReadRow\x12).google.bigtable.testproxy.ReadRowRequest\x1a$.google.bigtable.testproxy.RowResult\"\x00\x12_\n\x08ReadRows\x12*.google.bigtable.testproxy.ReadRowsRequest\x1a%.google.bigtable.testproxy.RowsResult\"\x00\x12\x66\n\tMutateRow\x12+.google.bigtable.testproxy.MutateRowRequest\x1a*.google.bigtable.testproxy.MutateRowResult\"\x00\x12m\n\x0e\x42ulkMutateRows\x12,.google.bigtable.testproxy.MutateRowsRequest\x1a+.google.bigtable.testproxy.MutateRowsResult\"\x00\x12~\n\x11\x43heckAndMutateRow\x12\x33.google.bigtable.testproxy.CheckAndMutateRowRequest\x1a\x32.google.bigtable.testproxy.CheckAndMutateRowResult\"\x00\x12r\n\rSampleRowKeys\x12/.google.bigtable.testproxy.SampleRowKeysRequest\x1a..google.bigtable.testproxy.SampleRowKeysResult\"\x00\x12r\n\x12ReadModifyWriteRow\x12\x34.google.bigtable.testproxy.ReadModifyWriteRowRequest\x1a$.google.bigtable.testproxy.RowResult\"\x00\x1a\x34\xca\x41\x31\x62igtable-test-proxy-not-accessible.googleapis.comB6\n#com.google.cloud.bigtable.testproxyP\x01Z\r./testproxypbb\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ["google.protobuf.Duration", "google/protobuf/duration.proto"], - ["google.bigtable.v2.RowFilter", "google/bigtable/v2/data.proto"], - ["google.rpc.Status", "google/rpc/status.proto"], - ["google.bigtable.v2.ReadRowsRequest", "google/bigtable/v2/bigtable.proto"], - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module Google module Bigtable diff --git a/google-cloud-bigtable/test/test_proxy/lib/google/bigtable/testproxy/test_proxy_services_pb.rb b/google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy_services_pb.rb similarity index 100% rename from google-cloud-bigtable/test/test_proxy/lib/google/bigtable/testproxy/test_proxy_services_pb.rb rename to google-cloud-bigtable/test/test_proxy/proto/google/bigtable/testproxy/test_proxy_services_pb.rb diff --git a/google-cloud-bigtable/test/test_proxy/test_proxy.rb b/google-cloud-bigtable/test/test_proxy/test_proxy.rb index 76d0c84169fa..2ff0f3041527 100644 --- a/google-cloud-bigtable/test/test_proxy/test_proxy.rb +++ b/google-cloud-bigtable/test/test_proxy/test_proxy.rb @@ -1,5 +1,5 @@ # Generated protos live here -$LOAD_PATH << File.join(__dir__, "lib") +$LOAD_PATH << File.join(__dir__, "proto") require "grpc" require "google/cloud/bigtable" @@ -88,8 +88,10 @@ def table name attr_accessor :instance_id attr_accessor :app_profile_id - def initialize client_id:, data_target:, project_id:, instance_id:, app_profile_id:, per_operation_timeout:, - optional_feature_config: + def initialize client_id:, data_target:, project_id:, instance_id:, + app_profile_id: nil, + per_operation_timeout: nil, + optional_feature_config: :OPTIONAL_FEATURE_CONFIG_DEFAULT LOGGER.debug "Building client #{client_id}"