Skip to content

Commit 69c9b61

Browse files
committed
Add support for adding tags to an Instance in InstanceConfig
1 parent 07a9fce commit 69c9b61

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

google/cloud/bigtable/instance_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ class InstanceConfig {
6767
return *this;
6868
}
6969

70+
InstanceConfig& insert_tag(std::string const& key, std::string const& value) {
71+
(*proto_.mutable_instance()->mutable_tags())[key] = value;
72+
return *this;
73+
}
74+
75+
InstanceConfig& emplace_tag(std::string const& key, std::string value) {
76+
(*proto_.mutable_instance()->mutable_tags())[key] = std::move(value);
77+
return *this;
78+
}
79+
7080
// NOLINT: accessors can (and should) be snake_case.
7181
google::bigtable::admin::v2::CreateInstanceRequest const& as_proto() const& {
7282
return proto_;

google/cloud/bigtable/instance_config_test.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ TEST(InstanceConfigTest, SetLabels) {
7575
EXPECT_EQ("qux", proto.instance().labels().at("baz"));
7676
}
7777

78+
79+
TEST(InstanceConfigTest, SetTags) {
80+
InstanceConfig config("my-instance", "pretty name",
81+
{
82+
{"cluster-1", {"somewhere", 7, ClusterConfig::SSD}},
83+
});
84+
85+
config.insert_tag("tagKeys/123", "tagValues/654").emplace_tag("tagKeys/345", "tagValues/987");
86+
87+
auto proto = config.as_proto();
88+
EXPECT_EQ("my-instance", proto.instance_id());
89+
EXPECT_EQ("pretty name", proto.instance().display_name());
90+
ASSERT_EQ(1, proto.clusters_size());
91+
92+
ASSERT_EQ(2, proto.instance().tags_size());
93+
EXPECT_EQ("tagValues/654", proto.instance().tags().at("tagKeys/123"));
94+
EXPECT_EQ("tagValues/987", proto.instance().tags().at("tagKeys/345"));
95+
}
96+
97+
7898
} // namespace
7999
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
80100
} // namespace bigtable

0 commit comments

Comments
 (0)