2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[709-cb_cmds-add-support-for-commands-to-manage-the-servers] Added delServerTag

This commit is contained in:
Francis Dupont
2019-06-30 15:28:19 +02:00
parent f693084db5
commit 3d618610fc
4 changed files with 41 additions and 2 deletions

View File

@@ -23,6 +23,17 @@ StampedElement::hasServerTag(const ServerTag& server_tag) const {
return (false);
}
void
StampedElement::delServerTag(const std::string& server_tag) {
for (auto it = server_tags_.begin(); it < server_tags_.end(); ++it) {
if (it->get() == server_tag) {
server_tags_.erase(it);
return;
}
}
isc_throw(NotFound, "can't find server tag '" << server_tag << "' to delete");
}
bool
StampedElement::hasAllServerTag() const {
return (hasServerTag(ServerTag(ServerTag::ALL)));

View File

@@ -47,6 +47,14 @@ public:
server_tags_.push_back(ServerTag(server_tag));
}
/// @brief Deletes server tag.
///
/// Remove the first occurrence of the given server tag.
///
/// @param server_tag server tag to delete.
/// @throw NotFound if the server tag cannot be found.
void delServerTag(const std::string& server_tag);
/// @brief Returns server tags.
///
/// @return Server tag as string.

View File

@@ -71,7 +71,7 @@ TEST(StampedElementTest, update) {
}
// Tests that one or more server tag can be specified.
TEST(StampedElementTest, setServerTags) {
TEST(StampedElementTest, setServerTag) {
StampedElement element;
element.setServerTag("foo");
EXPECT_EQ(1, element.getServerTags().size());
@@ -91,6 +91,26 @@ TEST(StampedElementTest, setServerTags) {
EXPECT_TRUE(element.hasAllServerTag());
}
// Tests that a server tag can be deleted.
TEST(StampedElementTest, delServerTag) {
StampedElement element;
EXPECT_THROW(element.delServerTag("foo"), isc::NotFound);
element.setServerTag("foo");
element.setServerTag("foo");
ASSERT_EQ(2, element.getServerTags().size());
EXPECT_EQ("foo", element.getServerTags()[0].get());
EXPECT_EQ("foo", element.getServerTags()[1].get());
EXPECT_NO_THROW(element.delServerTag("foo"));
ASSERT_EQ(1, element.getServerTags().size());
EXPECT_EQ("foo", element.getServerTags()[0].get());
EXPECT_NO_THROW(element.delServerTag("foo"));
EXPECT_EQ(0, element.getServerTags().size());
EXPECT_THROW(element.delServerTag("foo"), isc::NotFound);
}
// Test that metadata can be created from the StampedElement.
TEST(StampedElementTest, getMetadata) {
StampedElement element;