Skip to content

Commit

Permalink
cleanup(mixin): add more test cases (#14818)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiy0006 authored Nov 5, 2024
1 parent 6ab4a8c commit f0d92a0
Show file tree
Hide file tree
Showing 72 changed files with 1,519 additions and 106 deletions.
14 changes: 14 additions & 0 deletions generator/integration_tests/benchmarks/client_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "google/cloud/log.h"
#include "google/cloud/version.h"
#include <google/cloud/location/locations.grpc.pb.h>
#include <google/iam/v1/iam_policy.grpc.pb.h>
#include <google/longrunning/operations.grpc.pb.h>
#include <benchmark/benchmark.h>
#include <memory>

Expand Down Expand Up @@ -151,6 +153,18 @@ class TestStub : public GoldenKitchenSinkStub {
return internal::UnimplementedError("unimplemented");
}

StatusOr<google::iam::v1::Policy> GetIamPolicy(
grpc::ClientContext&, Options const&,
google::iam::v1::GetIamPolicyRequest const&) override {
return internal::UnimplementedError("unimplemented");
}

StatusOr<google::longrunning::ListOperationsResponse> ListOperations(
grpc::ClientContext&, Options const&,
google::longrunning::ListOperationsRequest const&) override {
return internal::UnimplementedError("unimplemented");
}

std::unique_ptr<::google::cloud::internal::AsyncStreamingReadRpc<
google::test::admin::database::v1::Response>>
AsyncStreamingRead(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ GoldenKitchenSinkClient::GetLocation(google::cloud::location::GetLocationRequest
return connection_->GetLocation(request);
}

StatusOr<google::iam::v1::Policy>
GoldenKitchenSinkClient::GetIamPolicy(google::iam::v1::GetIamPolicyRequest const& request, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
return connection_->GetIamPolicy(request);
}

StreamRange<google::longrunning::Operation>
GoldenKitchenSinkClient::ListOperations(std::string const& name, std::string const& filter, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
google::longrunning::ListOperationsRequest request;
request.set_name(name);
request.set_filter(filter);
return connection_->ListOperations(request);
}

StreamRange<google::longrunning::Operation>
GoldenKitchenSinkClient::ListOperations(google::longrunning::ListOperationsRequest request, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
return connection_->ListOperations(std::move(request));
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace golden_v1
} // namespace cloud
Expand Down
124 changes: 124 additions & 0 deletions generator/integration_tests/golden/v1/golden_kitchen_sink_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,130 @@ class GoldenKitchenSinkClient {
StatusOr<google::cloud::location::Location>
GetLocation(google::cloud::location::GetLocationRequest const& request, Options opts = {});

// clang-format off
///
/// Gets the access control policy for a resource.
/// Returns an empty policy if the resource exists and does not have a policy
/// set.
///
/// @param request Unary RPCs, such as the one wrapped by this
/// function, receive a single `request` proto message which includes all
/// the inputs for the RPC. In this case, the proto message is a
/// [google.iam.v1.GetIamPolicyRequest].
/// Proto messages are converted to C++ classes by Protobuf, using the
/// [Protobuf mapping rules].
/// @param opts Optional. Override the class-level options, such as retry and
/// backoff policies.
/// @return the result of the RPC. The response message type
/// ([google.iam.v1.Policy])
/// is mapped to a C++ class using the [Protobuf mapping rules].
/// If the request fails, the [`StatusOr`] contains the error details.
///
/// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/
/// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator
/// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string
/// [`future`]: @ref google::cloud::future
/// [`StatusOr`]: @ref google::cloud::StatusOr
/// [`Status`]: @ref google::cloud::Status
/// [google.iam.v1.GetIamPolicyRequest]: @googleapis_reference_link{google/iam/v1/iam_policy.proto#L123}
/// [google.iam.v1.Policy]: @googleapis_reference_link{google/iam/v1/policy.proto#L102}
///
// clang-format on
StatusOr<google::iam::v1::Policy>
GetIamPolicy(google::iam::v1::GetIamPolicyRequest const& request, Options opts = {});

// clang-format off
///
/// Lists operations that match the specified filter in the request. If the
/// server doesn't support this method, it returns `UNIMPLEMENTED`.
///
/// NOTE: the `name` binding allows API services to override the binding
/// to use different resource name schemes, such as `users/*/operations`. To
/// override the binding, API services can add a binding such as
/// `"/v1/{name=users/*}/operations"` to their service configuration.
/// For backwards compatibility, the default name includes the operations
/// collection id, however overriding users must ensure the name binding
/// is the parent resource, without the operations collection id.
///
/// @param name The name of the operation's parent resource.
/// @param filter The standard list filter.
/// @param opts Optional. Override the class-level options, such as retry and
/// backoff policies.
/// @return a [StreamRange](@ref google::cloud::StreamRange)
/// to iterate of the results. See the documentation of this type for
/// details. In brief, this class has `begin()` and `end()` member
/// functions returning a iterator class meeting the
/// [input iterator requirements]. The value type for this iterator is a
/// [`StatusOr`] as the iteration may fail even after some values are
/// retrieved successfully, for example, if there is a network disconnect.
/// An empty set of results does not indicate an error, it indicates
/// that there are no resources meeting the request criteria.
/// On a successful iteration the `StatusOr<T>` contains elements of type
/// [google.longrunning.Operation], or rather,
/// the C++ class generated by Protobuf from that type. Please consult the
/// Protobuf documentation for details on the [Protobuf mapping rules].
///
/// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/
/// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator
/// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string
/// [`future`]: @ref google::cloud::future
/// [`StatusOr`]: @ref google::cloud::StatusOr
/// [`Status`]: @ref google::cloud::Status
/// [google.longrunning.ListOperationsRequest]: @googleapis_reference_link{google/longrunning/operations.proto#L171}
/// [google.longrunning.Operation]: @googleapis_reference_link{google/longrunning/operations.proto#L128}
///
// clang-format on
StreamRange<google::longrunning::Operation>
ListOperations(std::string const& name, std::string const& filter, Options opts = {});

// clang-format off
///
/// Lists operations that match the specified filter in the request. If the
/// server doesn't support this method, it returns `UNIMPLEMENTED`.
///
/// NOTE: the `name` binding allows API services to override the binding
/// to use different resource name schemes, such as `users/*/operations`. To
/// override the binding, API services can add a binding such as
/// `"/v1/{name=users/*}/operations"` to their service configuration.
/// For backwards compatibility, the default name includes the operations
/// collection id, however overriding users must ensure the name binding
/// is the parent resource, without the operations collection id.
///
/// @param request Unary RPCs, such as the one wrapped by this
/// function, receive a single `request` proto message which includes all
/// the inputs for the RPC. In this case, the proto message is a
/// [google.longrunning.ListOperationsRequest].
/// Proto messages are converted to C++ classes by Protobuf, using the
/// [Protobuf mapping rules].
/// @param opts Optional. Override the class-level options, such as retry and
/// backoff policies.
/// @return a [StreamRange](@ref google::cloud::StreamRange)
/// to iterate of the results. See the documentation of this type for
/// details. In brief, this class has `begin()` and `end()` member
/// functions returning a iterator class meeting the
/// [input iterator requirements]. The value type for this iterator is a
/// [`StatusOr`] as the iteration may fail even after some values are
/// retrieved successfully, for example, if there is a network disconnect.
/// An empty set of results does not indicate an error, it indicates
/// that there are no resources meeting the request criteria.
/// On a successful iteration the `StatusOr<T>` contains elements of type
/// [google.longrunning.Operation], or rather,
/// the C++ class generated by Protobuf from that type. Please consult the
/// Protobuf documentation for details on the [Protobuf mapping rules].
///
/// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/
/// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator
/// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string
/// [`future`]: @ref google::cloud::future
/// [`StatusOr`]: @ref google::cloud::StatusOr
/// [`Status`]: @ref google::cloud::Status
/// [google.longrunning.ListOperationsRequest]: @googleapis_reference_link{google/longrunning/operations.proto#L171}
/// [google.longrunning.Operation]: @googleapis_reference_link{google/longrunning/operations.proto#L128}
///
// clang-format on
StreamRange<google::longrunning::Operation>
ListOperations(google::longrunning::ListOperationsRequest request, Options opts = {});

private:
std::shared_ptr<GoldenKitchenSinkConnection> connection_;
Options options_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ GoldenKitchenSinkConnection::GetLocation(
return Status(StatusCode::kUnimplemented, "not implemented");
}

StatusOr<google::iam::v1::Policy>
GoldenKitchenSinkConnection::GetIamPolicy(
google::iam::v1::GetIamPolicyRequest const&) {
return Status(StatusCode::kUnimplemented, "not implemented");
}

StreamRange<google::longrunning::Operation> GoldenKitchenSinkConnection::ListOperations(
google::longrunning::ListOperationsRequest) { // NOLINT(performance-unnecessary-value-param)
return google::cloud::internal::MakeUnimplementedPaginationRange<
StreamRange<google::longrunning::Operation>>();
}

std::shared_ptr<GoldenKitchenSinkConnection> MakeGoldenKitchenSinkConnection(
Options options) {
internal::CheckExpectedOptions<CommonOptionList, GrpcOptionList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ class GoldenKitchenSinkConnection {

virtual StatusOr<google::cloud::location::Location>
GetLocation(google::cloud::location::GetLocationRequest const& request);

virtual StatusOr<google::iam::v1::Policy>
GetIamPolicy(google::iam::v1::GetIamPolicyRequest const& request);

virtual StreamRange<google::longrunning::Operation>
ListOperations(google::longrunning::ListOperationsRequest request);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Idempotency GoldenKitchenSinkConnectionIdempotencyPolicy::GetLocation(google::cl
return Idempotency::kIdempotent;
}

Idempotency GoldenKitchenSinkConnectionIdempotencyPolicy::GetIamPolicy(google::iam::v1::GetIamPolicyRequest const&) {
return Idempotency::kIdempotent;
}

Idempotency GoldenKitchenSinkConnectionIdempotencyPolicy::ListOperations(google::longrunning::ListOperationsRequest) { // NOLINT
return Idempotency::kIdempotent;
}

std::unique_ptr<GoldenKitchenSinkConnectionIdempotencyPolicy>
MakeDefaultGoldenKitchenSinkConnectionIdempotencyPolicy() {
return std::make_unique<GoldenKitchenSinkConnectionIdempotencyPolicy>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "google/cloud/version.h"
#include <generator/integration_tests/test.grpc.pb.h>
#include <google/cloud/location/locations.grpc.pb.h>
#include <google/iam/v1/iam_policy.grpc.pb.h>
#include <google/longrunning/operations.grpc.pb.h>
#include <memory>

namespace google {
Expand Down Expand Up @@ -66,6 +68,12 @@ class GoldenKitchenSinkConnectionIdempotencyPolicy {

virtual google::cloud::Idempotency
GetLocation(google::cloud::location::GetLocationRequest const& request);

virtual google::cloud::Idempotency
GetIamPolicy(google::iam::v1::GetIamPolicyRequest const& request);

virtual google::cloud::Idempotency
ListOperations(google::longrunning::ListOperationsRequest request);
};

std::unique_ptr<GoldenKitchenSinkConnectionIdempotencyPolicy>
Expand Down
15 changes: 15 additions & 0 deletions generator/integration_tests/golden/v1/golden_thing_admin_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ GoldenThingAdminClient::GetLocation(google::cloud::location::GetLocationRequest
return connection_->GetLocation(request);
}

StreamRange<google::longrunning::Operation>
GoldenThingAdminClient::ListOperations(std::string const& name, std::string const& filter, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
google::longrunning::ListOperationsRequest request;
request.set_name(name);
request.set_filter(filter);
return connection_->ListOperations(request);
}

StreamRange<google::longrunning::Operation>
GoldenThingAdminClient::ListOperations(google::longrunning::ListOperationsRequest request, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
return connection_->ListOperations(std::move(request));
}

future<StatusOr<google::test::admin::database::v1::Database>>
GoldenThingAdminClient::AsyncGetDatabase(std::string const& name, Options opts) {
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
Expand Down
92 changes: 92 additions & 0 deletions generator/integration_tests/golden/v1/golden_thing_admin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,98 @@ class GoldenThingAdminClient {
StatusOr<google::cloud::location::Location>
GetLocation(google::cloud::location::GetLocationRequest const& request, Options opts = {});

// clang-format off
///
/// Lists operations that match the specified filter in the request. If the
/// server doesn't support this method, it returns `UNIMPLEMENTED`.
///
/// NOTE: the `name` binding allows API services to override the binding
/// to use different resource name schemes, such as `users/*/operations`. To
/// override the binding, API services can add a binding such as
/// `"/v1/{name=users/*}/operations"` to their service configuration.
/// For backwards compatibility, the default name includes the operations
/// collection id, however overriding users must ensure the name binding
/// is the parent resource, without the operations collection id.
///
/// @param name The name of the operation's parent resource.
/// @param filter The standard list filter.
/// @param opts Optional. Override the class-level options, such as retry and
/// backoff policies.
/// @return a [StreamRange](@ref google::cloud::StreamRange)
/// to iterate of the results. See the documentation of this type for
/// details. In brief, this class has `begin()` and `end()` member
/// functions returning a iterator class meeting the
/// [input iterator requirements]. The value type for this iterator is a
/// [`StatusOr`] as the iteration may fail even after some values are
/// retrieved successfully, for example, if there is a network disconnect.
/// An empty set of results does not indicate an error, it indicates
/// that there are no resources meeting the request criteria.
/// On a successful iteration the `StatusOr<T>` contains elements of type
/// [google.longrunning.Operation], or rather,
/// the C++ class generated by Protobuf from that type. Please consult the
/// Protobuf documentation for details on the [Protobuf mapping rules].
///
/// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/
/// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator
/// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string
/// [`future`]: @ref google::cloud::future
/// [`StatusOr`]: @ref google::cloud::StatusOr
/// [`Status`]: @ref google::cloud::Status
/// [google.longrunning.ListOperationsRequest]: @googleapis_reference_link{google/longrunning/operations.proto#L171}
/// [google.longrunning.Operation]: @googleapis_reference_link{google/longrunning/operations.proto#L128}
///
// clang-format on
StreamRange<google::longrunning::Operation>
ListOperations(std::string const& name, std::string const& filter, Options opts = {});

// clang-format off
///
/// Lists operations that match the specified filter in the request. If the
/// server doesn't support this method, it returns `UNIMPLEMENTED`.
///
/// NOTE: the `name` binding allows API services to override the binding
/// to use different resource name schemes, such as `users/*/operations`. To
/// override the binding, API services can add a binding such as
/// `"/v1/{name=users/*}/operations"` to their service configuration.
/// For backwards compatibility, the default name includes the operations
/// collection id, however overriding users must ensure the name binding
/// is the parent resource, without the operations collection id.
///
/// @param request Unary RPCs, such as the one wrapped by this
/// function, receive a single `request` proto message which includes all
/// the inputs for the RPC. In this case, the proto message is a
/// [google.longrunning.ListOperationsRequest].
/// Proto messages are converted to C++ classes by Protobuf, using the
/// [Protobuf mapping rules].
/// @param opts Optional. Override the class-level options, such as retry and
/// backoff policies.
/// @return a [StreamRange](@ref google::cloud::StreamRange)
/// to iterate of the results. See the documentation of this type for
/// details. In brief, this class has `begin()` and `end()` member
/// functions returning a iterator class meeting the
/// [input iterator requirements]. The value type for this iterator is a
/// [`StatusOr`] as the iteration may fail even after some values are
/// retrieved successfully, for example, if there is a network disconnect.
/// An empty set of results does not indicate an error, it indicates
/// that there are no resources meeting the request criteria.
/// On a successful iteration the `StatusOr<T>` contains elements of type
/// [google.longrunning.Operation], or rather,
/// the C++ class generated by Protobuf from that type. Please consult the
/// Protobuf documentation for details on the [Protobuf mapping rules].
///
/// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/
/// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator
/// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string
/// [`future`]: @ref google::cloud::future
/// [`StatusOr`]: @ref google::cloud::StatusOr
/// [`Status`]: @ref google::cloud::Status
/// [google.longrunning.ListOperationsRequest]: @googleapis_reference_link{google/longrunning/operations.proto#L171}
/// [google.longrunning.Operation]: @googleapis_reference_link{google/longrunning/operations.proto#L128}
///
// clang-format on
StreamRange<google::longrunning::Operation>
ListOperations(google::longrunning::ListOperationsRequest request, Options opts = {});

// clang-format off
///
/// Gets the state of a Cloud Test database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ GoldenThingAdminConnection::GetLocation(
return Status(StatusCode::kUnimplemented, "not implemented");
}

StreamRange<google::longrunning::Operation> GoldenThingAdminConnection::ListOperations(
google::longrunning::ListOperationsRequest) { // NOLINT(performance-unnecessary-value-param)
return google::cloud::internal::MakeUnimplementedPaginationRange<
StreamRange<google::longrunning::Operation>>();
}

future<StatusOr<google::test::admin::database::v1::Database>>
GoldenThingAdminConnection::AsyncGetDatabase(
google::test::admin::database::v1::GetDatabaseRequest const&) {
Expand Down
Loading

0 comments on commit f0d92a0

Please sign in to comment.