summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2019-06-30 15:28:19 +0200
committerFrancis Dupont <fdupont@isc.org>2019-07-04 01:10:51 +0200
commit3d618610fc2d4fe6e4a01b447b22ea03bf1a4d2d (patch)
tree5eb38440845f60da3e8cfca52a4065384e311d5e /src/lib
parent[550-authentication-key-to-text-method-miss-spelled] Added ChangeLog entry fo... (diff)
downloadkea-3d618610fc2d4fe6e4a01b447b22ea03bf1a4d2d.tar.xz
kea-3d618610fc2d4fe6e4a01b447b22ea03bf1a4d2d.zip
[709-cb_cmds-add-support-for-commands-to-manage-the-servers] Added delServerTag
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cc/base_stamped_element.h2
-rw-r--r--src/lib/cc/stamped_element.cc11
-rw-r--r--src/lib/cc/stamped_element.h8
-rw-r--r--src/lib/cc/tests/stamped_element_unittest.cc22
4 files changed, 41 insertions, 2 deletions
diff --git a/src/lib/cc/base_stamped_element.h b/src/lib/cc/base_stamped_element.h
index 11cb4e670b..e98bd32226 100644
--- a/src/lib/cc/base_stamped_element.h
+++ b/src/lib/cc/base_stamped_element.h
@@ -67,7 +67,7 @@ protected:
/// @brief Database identifier of the configuration element.
///
/// The default value of 0 indicates that the identifier is
- /// not set.
+ /// not set.
uint64_t id_;
/// @brief Holds timestamp value.
diff --git a/src/lib/cc/stamped_element.cc b/src/lib/cc/stamped_element.cc
index 2384108b3f..7a36e0cce4 100644
--- a/src/lib/cc/stamped_element.cc
+++ b/src/lib/cc/stamped_element.cc
@@ -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)));
diff --git a/src/lib/cc/stamped_element.h b/src/lib/cc/stamped_element.h
index 892b928730..f470fc9b99 100644
--- a/src/lib/cc/stamped_element.h
+++ b/src/lib/cc/stamped_element.h
@@ -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.
diff --git a/src/lib/cc/tests/stamped_element_unittest.cc b/src/lib/cc/tests/stamped_element_unittest.cc
index 80d170ef59..53b8598074 100644
--- a/src/lib/cc/tests/stamped_element_unittest.cc
+++ b/src/lib/cc/tests/stamped_element_unittest.cc
@@ -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;