Skip to content

Commit 5f42238

Browse files
authored
cleanup(pubsub): remove topic and subscription handwritten admin api helper functions (#13742)
* cleanup(pubsub): remove topic and subscription handwritten admin api helper functions * fix build issues by including schema.h * add schema * add snapshotg * chheckers
1 parent 62d55a3 commit 5f42238

File tree

5 files changed

+4
-124
lines changed

5 files changed

+4
-124
lines changed

google/cloud/pubsub/samples/pubsub_samples_common.cc

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

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

77-
google::cloud::testing_util::Commands::value_type CreateTopicAdminCommand(
78-
std::string const& name, std::vector<std::string> const& arg_names,
79-
TopicAdminCommand const& command) {
80-
auto adapter = [=](std::vector<std::string> const& argv) {
81-
if ((argv.size() == 1 && argv[0] == "--help") ||
82-
argv.size() != arg_names.size()) {
83-
std::ostringstream os;
84-
os << name;
85-
for (auto const& a : arg_names) {
86-
os << " <" << a << ">";
87-
}
88-
throw google::cloud::testing_util::Usage{std::move(os).str()};
89-
}
90-
google::cloud::pubsub::TopicAdminClient client(
91-
google::cloud::pubsub::MakeTopicAdminConnection());
92-
command(std::move(client), std::move(argv));
93-
};
94-
return google::cloud::testing_util::Commands::value_type{name,
95-
std::move(adapter)};
96-
}
97-
98-
google::cloud::testing_util::Commands::value_type
99-
CreateSubscriptionAdminCommand(std::string const& name,
100-
std::vector<std::string> const& arg_names,
101-
SubscriptionAdminCommand const& command) {
102-
auto adapter = [=](std::vector<std::string> const& argv) {
103-
if ((argv.size() == 1 && argv[0] == "--help") ||
104-
argv.size() != arg_names.size()) {
105-
std::ostringstream os;
106-
os << name;
107-
for (auto const& a : arg_names) {
108-
os << " <" << a << ">";
109-
}
110-
throw google::cloud::testing_util::Usage{std::move(os).str()};
111-
}
112-
google::cloud::pubsub::SubscriptionAdminClient client(
113-
google::cloud::pubsub::MakeSubscriptionAdminConnection());
114-
command(std::move(client), std::move(argv));
115-
};
116-
return google::cloud::testing_util::Commands::value_type{name,
117-
std::move(adapter)};
118-
}
119-
12078
google::cloud::testing_util::Commands::value_type CreateSchemaServiceCommand(
12179
std::string const& name, std::vector<std::string> const& arg_names,
12280
SchemaServiceCommand const& command) {

google/cloud/pubsub/samples/pubsub_samples_common.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SAMPLES_PUBSUB_SAMPLES_COMMON_H
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SAMPLES_PUBSUB_SAMPLES_COMMON_H
1717

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

48-
using TopicAdminCommand = std::function<void(pubsub::TopicAdminClient,
49-
std::vector<std::string> const&)>;
50-
51-
google::cloud::testing_util::Commands::value_type CreateTopicAdminCommand(
52-
std::string const& name, std::vector<std::string> const& arg_names,
53-
TopicAdminCommand const& command);
54-
55-
using SubscriptionAdminCommand = std::function<void(
56-
pubsub::SubscriptionAdminClient, std::vector<std::string> const&)>;
57-
58-
google::cloud::testing_util::Commands::value_type
59-
CreateSubscriptionAdminCommand(std::string const& name,
60-
std::vector<std::string> const& arg_names,
61-
SubscriptionAdminCommand const& command);
62-
6344
using SchemaServiceCommand = std::function<void(
6445
pubsub::SchemaServiceClient, std::vector<std::string> const&)>;
6546

google/cloud/pubsub/samples/pubsub_samples_common_test.cc

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -88,68 +88,6 @@ TEST(PubSubSamplesCommon, SubscriberCommand) {
8888
EXPECT_EQ(1, call_count);
8989
}
9090

91-
TEST(PubSubSamplesCommon, TopicAdminCommand) {
92-
using ::google::cloud::testing_util::Usage;
93-
94-
// Pretend we are using the emulator to avoid loading the default
95-
// credentials from $HOME, which do not exist when running with Bazel.
96-
google::cloud::testing_util::ScopedEnvironment emulator(
97-
"PUBSUB_EMULATOR_HOST", "localhost:8085");
98-
int call_count = 0;
99-
auto command = [&call_count](pubsub::TopicAdminClient const&,
100-
std::vector<std::string> const& argv) {
101-
++call_count;
102-
ASSERT_EQ(2, argv.size());
103-
EXPECT_EQ("a", argv[0]);
104-
EXPECT_EQ("b", argv[1]);
105-
};
106-
auto const actual =
107-
CreateTopicAdminCommand("command-name", {"foo", "bar"}, command);
108-
EXPECT_EQ("command-name", actual.first);
109-
EXPECT_THROW(
110-
try { actual.second({}); } catch (Usage const& ex) {
111-
EXPECT_THAT(ex.what(), HasSubstr("command-name"));
112-
EXPECT_THAT(ex.what(), HasSubstr("foo"));
113-
EXPECT_THAT(ex.what(), HasSubstr("bar"));
114-
throw;
115-
},
116-
Usage);
117-
118-
ASSERT_NO_FATAL_FAILURE(actual.second({"a", "b"}));
119-
EXPECT_EQ(1, call_count);
120-
}
121-
122-
TEST(PubSubSamplesCommon, SubscriptionAdminCommand) {
123-
using ::google::cloud::testing_util::Usage;
124-
125-
// Pretend we are using the emulator to avoid loading the default
126-
// credentials from $HOME, which do not exist when running with Bazel.
127-
google::cloud::testing_util::ScopedEnvironment emulator(
128-
"PUBSUB_EMULATOR_HOST", "localhost:8085");
129-
int call_count = 0;
130-
auto command = [&call_count](pubsub::SubscriptionAdminClient const&,
131-
std::vector<std::string> const& argv) {
132-
++call_count;
133-
ASSERT_EQ(2, argv.size());
134-
EXPECT_EQ("a", argv[0]);
135-
EXPECT_EQ("b", argv[1]);
136-
};
137-
auto const actual =
138-
CreateSubscriptionAdminCommand("command-name", {"foo", "bar"}, command);
139-
EXPECT_EQ("command-name", actual.first);
140-
EXPECT_THROW(
141-
try { actual.second({}); } catch (Usage const& ex) {
142-
EXPECT_THAT(ex.what(), HasSubstr("command-name"));
143-
EXPECT_THAT(ex.what(), HasSubstr("foo"));
144-
EXPECT_THAT(ex.what(), HasSubstr("bar"));
145-
throw;
146-
},
147-
Usage);
148-
149-
ASSERT_NO_FATAL_FAILURE(actual.second({"a", "b"}));
150-
EXPECT_EQ(1, call_count);
151-
}
152-
15391
TEST(PubSubSamplesCommon, SchemaServiceCommand) {
15492
using ::google::cloud::testing_util::Usage;
15593

google/cloud/pubsub/samples/subscription_admin_samples.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "google/cloud/pubsub/admin/subscription_admin_client.h"
1616
#include "google/cloud/pubsub/admin/topic_admin_client.h"
1717
#include "google/cloud/pubsub/samples/pubsub_samples_common.h"
18+
#include "google/cloud/pubsub/schema.h"
19+
#include "google/cloud/pubsub/snapshot.h"
1820
#include "google/cloud/pubsub/subscription.h"
1921
#include "google/cloud/internal/getenv.h"
2022
#include "google/cloud/internal/random.h"

google/cloud/pubsub/samples/topic_admin_samples.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "google/cloud/pubsub/admin/subscription_admin_client.h"
1616
#include "google/cloud/pubsub/admin/topic_admin_client.h"
1717
#include "google/cloud/pubsub/samples/pubsub_samples_common.h"
18+
#include "google/cloud/pubsub/schema.h"
1819
#include "google/cloud/pubsub/subscription.h"
1920
#include "google/cloud/pubsub/topic.h"
2021
#include "google/cloud/internal/getenv.h"

0 commit comments

Comments
 (0)