Google Cloud C++ Client 2.10.1
C++ Client Library for Google Cloud Platform
Loading...
Searching...
No Matches
Functions
google::cloud::mocks Namespace Reference

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

Functions

Options const & CurrentOptions ()
 Retrieve options used in a client call. More...
 
template<typename T >
StreamRange< T > MakeStreamRange (std::vector< T > values, Status final_status={})
 Construct a StreamRange<T> for use in tests. More...
 

Detailed Description

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.

Function Documentation

◆ CurrentOptions()

Options const & google::cloud::mocks::CurrentOptions ( )
inline

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);
}
Options const & CurrentOptions()
Retrieve options used in a client call.
Definition: current_options.h:44

◆ MakeStreamRange()

template<typename T >
StreamRange< T > google::cloud::mocks::MakeStreamRange ( std::vector< T >  values,
Status  final_status = {} 
)

Construct a StreamRange<T> for use in tests.

Parameters
valuesThe successfully returned T values.
final_statusThe final Status of the range. Defaults to an OK Status.
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()
}
Holds a value or a Status indicating why there is no value.
Definition: status_or.h:89