Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customers can verify call options #10030

Closed
dbolduc opened this issue Oct 11, 2022 · 0 comments · Fixed by #11050
Closed

Customers can verify call options #10030

dbolduc opened this issue Oct 11, 2022 · 0 comments · Fixed by #11050
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@dbolduc
Copy link
Member

dbolduc commented Oct 11, 2022

Our APIs look like:

T Client::Foo(FooRequest const& request, Options options);
T Connection::Foo(FooReqeust const& request);

Customers can verify they are giving the right request to our library. They cannot verify that they are giving the right options to our library.

void MakeClientCall() {
  // This function can be unit tested by customers
  auto options = MakeCallOptions();

  // But they can never catch the difference between:
  client.Foo(req, options);
  // and...
  client.Foo(req); // oops I forgot to include the options.
}

I think the solution is to add:

namespace google::cloud::mocks {
/**
 * Verify per-call options
 * 
 * @code
 * TEST(Foo, CallOptions) {
 *   auto mock = std::make_shared<MockConnection>();
 *   EXPECT_CALL(*mock, Foo).WillOnce([] {
 *         auto options = google::cloud::mocks::GetCallOptions();
 *         EXPECT_THAT(options, ...);
 *       });
 *   auto client = Client(mock);
 *   DoThing(client);
 * }
 * @endcode
 */
Options GetCallOptions() {
  return internal::CurrentOptions();
}
}
@dbolduc dbolduc added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant