Namespace google::cloud::mocks (2.16.0)

Contains helpers for testing the Google Cloud C++ Client Libraries.

The symbols defined in this namespace are part of google-cloud-cpp's public API. Application developers may use them when mocking the client libraries in their own tests.

Functions

CurrentOptions()

Retrieve options used in a client call.

This would be used to verify configuration options from within a MockConnection. It provides a way for applications to test the difference between client.Foo(request, options) and client.Foo(request).

TEST(Foo, CallOptions) {
  auto mock = std::make_shared<MockConnection>();
  EXPECT_CALL(*mock, Foo).WillOnce([] {
        auto const& options = google::cloud::mocks::CurrentOptions();
        EXPECT_THAT(options, ...);
      });
  auto client = Client(mock);
  MyFunctionThatCallsFoo(client);
}
Returns
Type Description
Options const &

MakeStreamRange(std::vector< T >, Status)

Construct a StreamRange<T> for use in tests.

auto sr = MakeStreamRange<T>({t1, t2});
for (StatusOr<T> const& t : sr) {
  // Yields t1 -> t2
}

sr = MakeStreamRange<T>({t1, t2}, BadStatus());
for (StatusOr<T> const& t : sr) {
  // Yields t1 -> t2 -> BadStatus()
}
Parameters
Name Description
values

The successfully returned T values.

final_status

The final Status of the range. Defaults to an OK Status.

typename T
Returns
Type Description
StreamRange< T >