# frozen_string_literal: true

# Copyright 2021 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
#
#     https://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.

# Auto-generated by gapic-generator-ruby. DO NOT EDIT!

require "helper"

require "gapic/grpc/service_stub"

require "google/cloud/sql/v1/cloud_sql_instances_pb"
require "google/cloud/sql/v1/cloud_sql_instances_services_pb"
require "google/cloud/sql/v1/sql_instances_service"

class ::Google::Cloud::Sql::V1::SqlInstancesService::ClientTest < Minitest::Test
  class ClientStub
    attr_accessor :call_rpc_count, :requests

    def initialize response, operation, &block
      @response = response
      @operation = operation
      @block = block
      @call_rpc_count = 0
      @requests = []
    end

    def call_rpc *args, **kwargs
      @call_rpc_count += 1

      @requests << @block&.call(*args, **kwargs)

      yield @response, @operation if block_given?

      @response
    end
  end

  def test_add_server_ca
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    add_server_ca_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :add_server_ca, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesAddServerCaRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, add_server_ca_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.add_server_ca({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.add_server_ca instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.add_server_ca ::Google::Cloud::Sql::V1::SqlInstancesAddServerCaRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.add_server_ca({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.add_server_ca(::Google::Cloud::Sql::V1::SqlInstancesAddServerCaRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, add_server_ca_client_stub.call_rpc_count
    end
  end

  def test_call_clone
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    call_clone_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :call_clone, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesCloneRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesCloneRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, call_clone_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.call_clone({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.call_clone instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.call_clone ::Google::Cloud::Sql::V1::SqlInstancesCloneRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.call_clone({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.call_clone(::Google::Cloud::Sql::V1::SqlInstancesCloneRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, call_clone_client_stub.call_rpc_count
    end
  end

  def test_delete
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    delete_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :delete, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesDeleteRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, delete_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.delete({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.delete instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.delete ::Google::Cloud::Sql::V1::SqlInstancesDeleteRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.delete({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.delete(::Google::Cloud::Sql::V1::SqlInstancesDeleteRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, delete_client_stub.call_rpc_count
    end
  end

  def test_demote_master
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    demote_master_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :demote_master, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesDemoteMasterRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesDemoteMasterRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, demote_master_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.demote_master({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.demote_master instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.demote_master ::Google::Cloud::Sql::V1::SqlInstancesDemoteMasterRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.demote_master({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.demote_master(::Google::Cloud::Sql::V1::SqlInstancesDemoteMasterRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, demote_master_client_stub.call_rpc_count
    end
  end

  def test_export
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    export_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :export, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesExportRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesExportRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, export_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.export({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.export instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.export ::Google::Cloud::Sql::V1::SqlInstancesExportRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.export({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.export(::Google::Cloud::Sql::V1::SqlInstancesExportRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, export_client_stub.call_rpc_count
    end
  end

  def test_failover
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    failover_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :failover, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesFailoverRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesFailoverRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, failover_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.failover({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.failover instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.failover ::Google::Cloud::Sql::V1::SqlInstancesFailoverRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.failover({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.failover(::Google::Cloud::Sql::V1::SqlInstancesFailoverRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, failover_client_stub.call_rpc_count
    end
  end

  def test_get
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::DatabaseInstance.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    get_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :get, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesGetRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, get_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.get({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.get instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.get ::Google::Cloud::Sql::V1::SqlInstancesGetRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.get({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.get(::Google::Cloud::Sql::V1::SqlInstancesGetRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, get_client_stub.call_rpc_count
    end
  end

  def test_import
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    import_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :import, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesImportRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesImportRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, import_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.import({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.import instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.import ::Google::Cloud::Sql::V1::SqlInstancesImportRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.import({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.import(::Google::Cloud::Sql::V1::SqlInstancesImportRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, import_client_stub.call_rpc_count
    end
  end

  def test_insert
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    project = "hello world"
    body = {}

    insert_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :insert, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesInsertRequest, request
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::DatabaseInstance), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, insert_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.insert({ project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.insert project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.insert ::Google::Cloud::Sql::V1::SqlInstancesInsertRequest.new(project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.insert({ project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.insert(::Google::Cloud::Sql::V1::SqlInstancesInsertRequest.new(project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, insert_client_stub.call_rpc_count
    end
  end

  def test_list
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::InstancesListResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    filter = "hello world"
    max_results = 42
    page_token = "hello world"
    project = "hello world"

    list_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :list, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesListRequest, request
      assert_equal "hello world", request["filter"]
      assert_equal 42, request["max_results"]
      assert_equal "hello world", request["page_token"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, list_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.list({ filter: filter, max_results: max_results, page_token: page_token, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.list filter: filter, max_results: max_results, page_token: page_token, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.list ::Google::Cloud::Sql::V1::SqlInstancesListRequest.new(filter: filter, max_results: max_results, page_token: page_token, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.list({ filter: filter, max_results: max_results, page_token: page_token, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.list(::Google::Cloud::Sql::V1::SqlInstancesListRequest.new(filter: filter, max_results: max_results, page_token: page_token, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, list_client_stub.call_rpc_count
    end
  end

  def test_list_server_cas
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::InstancesListServerCasResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    list_server_cas_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :list_server_cas, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesListServerCasRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, list_server_cas_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.list_server_cas({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.list_server_cas instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.list_server_cas ::Google::Cloud::Sql::V1::SqlInstancesListServerCasRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.list_server_cas({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.list_server_cas(::Google::Cloud::Sql::V1::SqlInstancesListServerCasRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, list_server_cas_client_stub.call_rpc_count
    end
  end

  def test_patch
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    patch_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :patch, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesPatchRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::DatabaseInstance), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, patch_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.patch({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.patch instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.patch ::Google::Cloud::Sql::V1::SqlInstancesPatchRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.patch({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.patch(::Google::Cloud::Sql::V1::SqlInstancesPatchRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, patch_client_stub.call_rpc_count
    end
  end

  def test_promote_replica
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    promote_replica_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :promote_replica, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesPromoteReplicaRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, promote_replica_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.promote_replica({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.promote_replica instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.promote_replica ::Google::Cloud::Sql::V1::SqlInstancesPromoteReplicaRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.promote_replica({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.promote_replica(::Google::Cloud::Sql::V1::SqlInstancesPromoteReplicaRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, promote_replica_client_stub.call_rpc_count
    end
  end

  def test_reset_ssl_config
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    reset_ssl_config_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :reset_ssl_config, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesResetSslConfigRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, reset_ssl_config_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.reset_ssl_config({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.reset_ssl_config instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.reset_ssl_config ::Google::Cloud::Sql::V1::SqlInstancesResetSslConfigRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.reset_ssl_config({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.reset_ssl_config(::Google::Cloud::Sql::V1::SqlInstancesResetSslConfigRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, reset_ssl_config_client_stub.call_rpc_count
    end
  end

  def test_restart
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    restart_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :restart, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesRestartRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, restart_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.restart({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.restart instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.restart ::Google::Cloud::Sql::V1::SqlInstancesRestartRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.restart({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.restart(::Google::Cloud::Sql::V1::SqlInstancesRestartRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, restart_client_stub.call_rpc_count
    end
  end

  def test_restore_backup
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    restore_backup_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :restore_backup, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesRestoreBackupRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesRestoreBackupRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, restore_backup_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.restore_backup({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.restore_backup instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.restore_backup ::Google::Cloud::Sql::V1::SqlInstancesRestoreBackupRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.restore_backup({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.restore_backup(::Google::Cloud::Sql::V1::SqlInstancesRestoreBackupRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, restore_backup_client_stub.call_rpc_count
    end
  end

  def test_rotate_server_ca
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    rotate_server_ca_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :rotate_server_ca, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesRotateServerCaRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesRotateServerCaRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, rotate_server_ca_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.rotate_server_ca({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.rotate_server_ca instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.rotate_server_ca ::Google::Cloud::Sql::V1::SqlInstancesRotateServerCaRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.rotate_server_ca({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.rotate_server_ca(::Google::Cloud::Sql::V1::SqlInstancesRotateServerCaRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, rotate_server_ca_client_stub.call_rpc_count
    end
  end

  def test_start_replica
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    start_replica_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :start_replica, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesStartReplicaRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, start_replica_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.start_replica({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.start_replica instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.start_replica ::Google::Cloud::Sql::V1::SqlInstancesStartReplicaRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.start_replica({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.start_replica(::Google::Cloud::Sql::V1::SqlInstancesStartReplicaRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, start_replica_client_stub.call_rpc_count
    end
  end

  def test_stop_replica
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"

    stop_replica_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :stop_replica, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesStopReplicaRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, stop_replica_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.stop_replica({ instance: instance, project: project }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.stop_replica instance: instance, project: project do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.stop_replica ::Google::Cloud::Sql::V1::SqlInstancesStopReplicaRequest.new(instance: instance, project: project) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.stop_replica({ instance: instance, project: project }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.stop_replica(::Google::Cloud::Sql::V1::SqlInstancesStopReplicaRequest.new(instance: instance, project: project), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, stop_replica_client_stub.call_rpc_count
    end
  end

  def test_truncate_log
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    truncate_log_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :truncate_log, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesTruncateLogRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::InstancesTruncateLogRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, truncate_log_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.truncate_log({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.truncate_log instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.truncate_log ::Google::Cloud::Sql::V1::SqlInstancesTruncateLogRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.truncate_log({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.truncate_log(::Google::Cloud::Sql::V1::SqlInstancesTruncateLogRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, truncate_log_client_stub.call_rpc_count
    end
  end

  def test_update
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    update_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :update, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesUpdateRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::DatabaseInstance), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, update_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.update({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.update instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.update ::Google::Cloud::Sql::V1::SqlInstancesUpdateRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.update({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.update(::Google::Cloud::Sql::V1::SqlInstancesUpdateRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, update_client_stub.call_rpc_count
    end
  end

  def test_create_ephemeral
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::SslCert.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    create_ephemeral_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :create_ephemeral, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesCreateEphemeralCertRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::SslCertsCreateEphemeralRequest), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, create_ephemeral_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.create_ephemeral({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.create_ephemeral instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.create_ephemeral ::Google::Cloud::Sql::V1::SqlInstancesCreateEphemeralCertRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.create_ephemeral({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.create_ephemeral(::Google::Cloud::Sql::V1::SqlInstancesCreateEphemeralCertRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, create_ephemeral_client_stub.call_rpc_count
    end
  end

  def test_reschedule_maintenance
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    body = {}

    reschedule_maintenance_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :reschedule_maintenance, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesRescheduleMaintenanceRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::SqlInstancesRescheduleMaintenanceRequestBody), request["body"]
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, reschedule_maintenance_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.reschedule_maintenance({ instance: instance, project: project, body: body }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.reschedule_maintenance instance: instance, project: project, body: body do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.reschedule_maintenance ::Google::Cloud::Sql::V1::SqlInstancesRescheduleMaintenanceRequest.new(instance: instance, project: project, body: body) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.reschedule_maintenance({ instance: instance, project: project, body: body }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.reschedule_maintenance(::Google::Cloud::Sql::V1::SqlInstancesRescheduleMaintenanceRequest.new(instance: instance, project: project, body: body), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, reschedule_maintenance_client_stub.call_rpc_count
    end
  end

  def test_verify_external_sync_settings
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::SqlInstancesVerifyExternalSyncSettingsResponse.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    verify_connection_only = true
    sync_mode = :EXTERNAL_SYNC_MODE_UNSPECIFIED
    verify_replication_only = true
    mysql_sync_config = {}

    verify_external_sync_settings_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :verify_external_sync_settings, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesVerifyExternalSyncSettingsRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal true, request["verify_connection_only"]
      assert_equal :EXTERNAL_SYNC_MODE_UNSPECIFIED, request["sync_mode"]
      assert_equal true, request["verify_replication_only"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::MySqlSyncConfig), request["mysql_sync_config"]
      assert_equal :mysql_sync_config, request.sync_config
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, verify_external_sync_settings_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.verify_external_sync_settings({ instance: instance, project: project, verify_connection_only: verify_connection_only, sync_mode: sync_mode, verify_replication_only: verify_replication_only, mysql_sync_config: mysql_sync_config }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.verify_external_sync_settings instance: instance, project: project, verify_connection_only: verify_connection_only, sync_mode: sync_mode, verify_replication_only: verify_replication_only, mysql_sync_config: mysql_sync_config do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.verify_external_sync_settings ::Google::Cloud::Sql::V1::SqlInstancesVerifyExternalSyncSettingsRequest.new(instance: instance, project: project, verify_connection_only: verify_connection_only, sync_mode: sync_mode, verify_replication_only: verify_replication_only, mysql_sync_config: mysql_sync_config) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.verify_external_sync_settings({ instance: instance, project: project, verify_connection_only: verify_connection_only, sync_mode: sync_mode, verify_replication_only: verify_replication_only, mysql_sync_config: mysql_sync_config }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.verify_external_sync_settings(::Google::Cloud::Sql::V1::SqlInstancesVerifyExternalSyncSettingsRequest.new(instance: instance, project: project, verify_connection_only: verify_connection_only, sync_mode: sync_mode, verify_replication_only: verify_replication_only, mysql_sync_config: mysql_sync_config), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, verify_external_sync_settings_client_stub.call_rpc_count
    end
  end

  def test_start_external_sync
    # Create GRPC objects.
    grpc_response = ::Google::Cloud::Sql::V1::Operation.new
    grpc_operation = GRPC::ActiveCall::Operation.new nil
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
    grpc_options = {}

    # Create request parameters for a unary method.
    instance = "hello world"
    project = "hello world"
    sync_mode = :EXTERNAL_SYNC_MODE_UNSPECIFIED
    skip_verification = true
    mysql_sync_config = {}

    start_external_sync_client_stub = ClientStub.new grpc_response, grpc_operation do |name, request, options:|
      assert_equal :start_external_sync, name
      assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesStartExternalSyncRequest, request
      assert_equal "hello world", request["instance"]
      assert_equal "hello world", request["project"]
      assert_equal :EXTERNAL_SYNC_MODE_UNSPECIFIED, request["sync_mode"]
      assert_equal true, request["skip_verification"]
      assert_equal Gapic::Protobuf.coerce({}, to: ::Google::Cloud::Sql::V1::MySqlSyncConfig), request["mysql_sync_config"]
      assert_equal :mysql_sync_config, request.sync_config
      refute_nil options
    end

    Gapic::ServiceStub.stub :new, start_external_sync_client_stub do
      # Create client
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end

      # Use hash object
      client.start_external_sync({ instance: instance, project: project, sync_mode: sync_mode, skip_verification: skip_verification, mysql_sync_config: mysql_sync_config }) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use named arguments
      client.start_external_sync instance: instance, project: project, sync_mode: sync_mode, skip_verification: skip_verification, mysql_sync_config: mysql_sync_config do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object
      client.start_external_sync ::Google::Cloud::Sql::V1::SqlInstancesStartExternalSyncRequest.new(instance: instance, project: project, sync_mode: sync_mode, skip_verification: skip_verification, mysql_sync_config: mysql_sync_config) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use hash object with options
      client.start_external_sync({ instance: instance, project: project, sync_mode: sync_mode, skip_verification: skip_verification, mysql_sync_config: mysql_sync_config }, grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Use protobuf object with options
      client.start_external_sync(::Google::Cloud::Sql::V1::SqlInstancesStartExternalSyncRequest.new(instance: instance, project: project, sync_mode: sync_mode, skip_verification: skip_verification, mysql_sync_config: mysql_sync_config), grpc_options) do |response, operation|
        assert_equal grpc_response, response
        assert_equal grpc_operation, operation
      end

      # Verify method calls
      assert_equal 5, start_external_sync_client_stub.call_rpc_count
    end
  end

  def test_configure
    grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure

    client = block_config = config = nil
    Gapic::ServiceStub.stub :new, nil do
      client = ::Google::Cloud::Sql::V1::SqlInstancesService::Client.new do |config|
        config.credentials = grpc_channel
      end
    end

    config = client.configure do |c|
      block_config = c
    end

    assert_same block_config, config
    assert_kind_of ::Google::Cloud::Sql::V1::SqlInstancesService::Client::Configuration, config
  end
end
