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

cleanup(pubsub): remove topic and subscription handwritten admin api helper functions #13742

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 1 addition & 43 deletions google/cloud/pubsub/samples/pubsub_samples_common.cc
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
// limitations under the License.

#include "google/cloud/pubsub/samples/pubsub_samples_common.h"
#include "google/cloud/pubsub/schema.h"
#include "google/cloud/pubsub/testing/random_names.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/time_utils.h"
@@ -74,49 +75,6 @@ google::cloud::testing_util::Commands::value_type CreateSubscriberCommand(
std::move(adapter)};
}

google::cloud::testing_util::Commands::value_type CreateTopicAdminCommand(
std::string const& name, std::vector<std::string> const& arg_names,
TopicAdminCommand const& command) {
auto adapter = [=](std::vector<std::string> const& argv) {
if ((argv.size() == 1 && argv[0] == "--help") ||
argv.size() != arg_names.size()) {
std::ostringstream os;
os << name;
for (auto const& a : arg_names) {
os << " <" << a << ">";
}
throw google::cloud::testing_util::Usage{std::move(os).str()};
}
google::cloud::pubsub::TopicAdminClient client(
google::cloud::pubsub::MakeTopicAdminConnection());
command(std::move(client), std::move(argv));
};
return google::cloud::testing_util::Commands::value_type{name,
std::move(adapter)};
}

google::cloud::testing_util::Commands::value_type
CreateSubscriptionAdminCommand(std::string const& name,
std::vector<std::string> const& arg_names,
SubscriptionAdminCommand const& command) {
auto adapter = [=](std::vector<std::string> const& argv) {
if ((argv.size() == 1 && argv[0] == "--help") ||
argv.size() != arg_names.size()) {
std::ostringstream os;
os << name;
for (auto const& a : arg_names) {
os << " <" << a << ">";
}
throw google::cloud::testing_util::Usage{std::move(os).str()};
}
google::cloud::pubsub::SubscriptionAdminClient client(
google::cloud::pubsub::MakeSubscriptionAdminConnection());
command(std::move(client), std::move(argv));
};
return google::cloud::testing_util::Commands::value_type{name,
std::move(adapter)};
}

google::cloud::testing_util::Commands::value_type CreateSchemaServiceCommand(
std::string const& name, std::vector<std::string> const& arg_names,
SchemaServiceCommand const& command) {
19 changes: 0 additions & 19 deletions google/cloud/pubsub/samples/pubsub_samples_common.h
Original file line number Diff line number Diff line change
@@ -15,13 +15,9 @@
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SAMPLES_PUBSUB_SAMPLES_COMMON_H
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SAMPLES_PUBSUB_SAMPLES_COMMON_H

// TODO(#12987): Remove this file after the deprecation period expires
#include "google/cloud/internal/disable_deprecation_warnings.inc"
#include "google/cloud/pubsub/publisher.h"
#include "google/cloud/pubsub/schema_client.h"
#include "google/cloud/pubsub/subscriber.h"
#include "google/cloud/pubsub/subscription_admin_client.h"
#include "google/cloud/pubsub/topic_admin_client.h"
#include "google/cloud/testing_util/example_driver.h"
#include <string>
#include <vector>
@@ -45,21 +41,6 @@ google::cloud::testing_util::Commands::value_type CreateSubscriberCommand(
std::string const& name, std::vector<std::string> const& arg_names,
SubscriberCommand const& command);

using TopicAdminCommand = std::function<void(pubsub::TopicAdminClient,
std::vector<std::string> const&)>;

google::cloud::testing_util::Commands::value_type CreateTopicAdminCommand(
std::string const& name, std::vector<std::string> const& arg_names,
TopicAdminCommand const& command);

using SubscriptionAdminCommand = std::function<void(
pubsub::SubscriptionAdminClient, std::vector<std::string> const&)>;

google::cloud::testing_util::Commands::value_type
CreateSubscriptionAdminCommand(std::string const& name,
std::vector<std::string> const& arg_names,
SubscriptionAdminCommand const& command);

using SchemaServiceCommand = std::function<void(
pubsub::SchemaServiceClient, std::vector<std::string> const&)>;

62 changes: 0 additions & 62 deletions google/cloud/pubsub/samples/pubsub_samples_common_test.cc
Original file line number Diff line number Diff line change
@@ -88,68 +88,6 @@ TEST(PubSubSamplesCommon, SubscriberCommand) {
EXPECT_EQ(1, call_count);
}

TEST(PubSubSamplesCommon, TopicAdminCommand) {
using ::google::cloud::testing_util::Usage;

// Pretend we are using the emulator to avoid loading the default
// credentials from $HOME, which do not exist when running with Bazel.
google::cloud::testing_util::ScopedEnvironment emulator(
"PUBSUB_EMULATOR_HOST", "localhost:8085");
int call_count = 0;
auto command = [&call_count](pubsub::TopicAdminClient const&,
std::vector<std::string> const& argv) {
++call_count;
ASSERT_EQ(2, argv.size());
EXPECT_EQ("a", argv[0]);
EXPECT_EQ("b", argv[1]);
};
auto const actual =
CreateTopicAdminCommand("command-name", {"foo", "bar"}, command);
EXPECT_EQ("command-name", actual.first);
EXPECT_THROW(
try { actual.second({}); } catch (Usage const& ex) {
EXPECT_THAT(ex.what(), HasSubstr("command-name"));
EXPECT_THAT(ex.what(), HasSubstr("foo"));
EXPECT_THAT(ex.what(), HasSubstr("bar"));
throw;
},
Usage);

ASSERT_NO_FATAL_FAILURE(actual.second({"a", "b"}));
EXPECT_EQ(1, call_count);
}

TEST(PubSubSamplesCommon, SubscriptionAdminCommand) {
using ::google::cloud::testing_util::Usage;

// Pretend we are using the emulator to avoid loading the default
// credentials from $HOME, which do not exist when running with Bazel.
google::cloud::testing_util::ScopedEnvironment emulator(
"PUBSUB_EMULATOR_HOST", "localhost:8085");
int call_count = 0;
auto command = [&call_count](pubsub::SubscriptionAdminClient const&,
std::vector<std::string> const& argv) {
++call_count;
ASSERT_EQ(2, argv.size());
EXPECT_EQ("a", argv[0]);
EXPECT_EQ("b", argv[1]);
};
auto const actual =
CreateSubscriptionAdminCommand("command-name", {"foo", "bar"}, command);
EXPECT_EQ("command-name", actual.first);
EXPECT_THROW(
try { actual.second({}); } catch (Usage const& ex) {
EXPECT_THAT(ex.what(), HasSubstr("command-name"));
EXPECT_THAT(ex.what(), HasSubstr("foo"));
EXPECT_THAT(ex.what(), HasSubstr("bar"));
throw;
},
Usage);

ASSERT_NO_FATAL_FAILURE(actual.second({"a", "b"}));
EXPECT_EQ(1, call_count);
}

TEST(PubSubSamplesCommon, SchemaServiceCommand) {
using ::google::cloud::testing_util::Usage;

2 changes: 2 additions & 0 deletions google/cloud/pubsub/samples/subscription_admin_samples.cc
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
#include "google/cloud/pubsub/admin/subscription_admin_client.h"
#include "google/cloud/pubsub/admin/topic_admin_client.h"
#include "google/cloud/pubsub/samples/pubsub_samples_common.h"
#include "google/cloud/pubsub/schema.h"
#include "google/cloud/pubsub/snapshot.h"
#include "google/cloud/pubsub/subscription.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/random.h"
1 change: 1 addition & 0 deletions google/cloud/pubsub/samples/topic_admin_samples.cc
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#include "google/cloud/pubsub/admin/subscription_admin_client.h"
#include "google/cloud/pubsub/admin/topic_admin_client.h"
#include "google/cloud/pubsub/samples/pubsub_samples_common.h"
#include "google/cloud/pubsub/schema.h"
#include "google/cloud/pubsub/subscription.h"
#include "google/cloud/pubsub/topic.h"
#include "google/cloud/internal/getenv.h"