Skip to content
Snippets Groups Projects
Commit e410c5b6 authored by Eric Cano's avatar Eric Cano
Browse files

Added unit test checking that we cannot add duplicate entry and fixed the code.

parent 51f5e1c2
No related branches found
No related tags found
No related merge requests found
......@@ -104,7 +104,7 @@ void cta::objectstore::RootEntry::addAdminUser(const UserIdentity& user,
try {
serializers::findElement(m_payload.adminusers(), user);
throw DuplicateEntry("In RootEntry::addAdminUser: entry already exists");
} catch (...) {}
} catch (serializers::NotFound &) {}
serializers::AdminUser * au = m_payload.add_adminusers();
user.serialize(*au->mutable_user());
log.serialize(*au->mutable_log());
......@@ -153,7 +153,7 @@ void cta::objectstore::RootEntry::addStorageClass(const std::string storageClass
try {
serializers::findElement(m_payload.storageclasses(), storageClass);
throw DuplicateEntry("In RootEntry::addStorageClass: trying to create duplicate entry");
} catch (...) {}
} catch (serializers::NotFound &) {}
// Insert the storage class
auto * sc = m_payload.mutable_storageclasses()->Add();
sc->set_name(storageClass);
......
......@@ -100,6 +100,17 @@ TEST(RootEntry, AdminHosts) {
re.removeAdminHost("noSuch");
re.commit();
}
{
// Check that we cannot re-add an existing host
// Check that we can remove existing and non-existing hosts
cta::objectstore::RootEntry re(be);
cta::objectstore::ScopedExclusiveLock lock(re);
re.fetch();
cta::objectstore::CreationLog cl(99, "dummyUser", 99, "dummyGroup",
"unittesthost", time(NULL), "Creation of unit test agent register");
ASSERT_THROW(re.addAdminHost("adminHost2", cl),
cta::objectstore::RootEntry::DuplicateEntry);
}
{
// Check that we got the expected result
cta::objectstore::RootEntry re(be);
......@@ -164,6 +175,17 @@ TEST(RootEntry, AdminUsers) {
re.removeAdminUser(user3);
re.commit();
}
{
// Check that we cannot re-add an existing user
// Check that we can remove existing and non-existing hosts
cta::objectstore::RootEntry re(be);
cta::objectstore::ScopedExclusiveLock lock(re);
re.fetch();
cta::objectstore::CreationLog cl(99, "dummyUser", 99, "dummyGroup",
"unittesthost", time(NULL), "Creation of unit test agent register");
ASSERT_THROW(re.addAdminUser(user2, cl),
cta::objectstore::RootEntry::DuplicateEntry);
}
{
// Check that we got the expected result
cta::objectstore::RootEntry re(be);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment