diff --git a/google/cloud/bigtable/instance_config.h b/google/cloud/bigtable/instance_config.h index c564067e8c4e3..0d99b8a46d7c0 100644 --- a/google/cloud/bigtable/instance_config.h +++ b/google/cloud/bigtable/instance_config.h @@ -67,6 +67,22 @@ class InstanceConfig { return *this; } + InstanceConfig& insert_tag(std::string const& key, std::string const& value) { + (*proto_.mutable_instance()->mutable_tags())[key] = value; + return *this; + } + + InstanceConfig& emplace_tag(std::string const& key, std::string value) { + (*proto_.mutable_instance()->mutable_tags())[key] = std::move(value); + return *this; + } + + InstanceConfig& emplace_tag(std::string&& key, std::string value) { + (*proto_.mutable_instance()->mutable_tags())[std::move(key)] = + std::move(value); + return *this; + } + // NOLINT: accessors can (and should) be snake_case. google::bigtable::admin::v2::CreateInstanceRequest const& as_proto() const& { return proto_; diff --git a/google/cloud/bigtable/instance_config_test.cc b/google/cloud/bigtable/instance_config_test.cc index 97afec1310caa..d6d2a47457ea2 100644 --- a/google/cloud/bigtable/instance_config_test.cc +++ b/google/cloud/bigtable/instance_config_test.cc @@ -75,6 +75,26 @@ TEST(InstanceConfigTest, SetLabels) { EXPECT_EQ("qux", proto.instance().labels().at("baz")); } + +TEST(InstanceConfigTest, SetTags) { + InstanceConfig config("my-instance", "pretty name", + { + {"cluster-1", {"somewhere", 7, ClusterConfig::SSD}}, + }); + + config.insert_tag("tagKeys/123", "tagValues/654").emplace_tag("tagKeys/345", "tagValues/987"); + + auto proto = config.as_proto(); + EXPECT_EQ("my-instance", proto.instance_id()); + EXPECT_EQ("pretty name", proto.instance().display_name()); + ASSERT_EQ(1, proto.clusters_size()); + + ASSERT_EQ(2, proto.instance().tags_size()); + EXPECT_EQ("tagValues/654", proto.instance().tags().at("tagKeys/123")); + EXPECT_EQ("tagValues/987", proto.instance().tags().at("tagKeys/345")); +} + + } // namespace GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace bigtable