Commit 1b5c7780 authored by Steven Murray's avatar Steven Murray
Browse files

Added unit-test createAdminUser_same_admin_twice

parent f14e3bc9
......@@ -34,8 +34,7 @@ cta::catalogue::SqliteCatalogue::SqliteCatalogue(): m_conn(":memory:") {
// createSchema
//------------------------------------------------------------------------------
void cta::catalogue::SqliteCatalogue::createDbSchema() {
m_conn.enableForeignKeys();
m_conn.execNonQuery(
const char *const sql =
"CREATE TABLE ADMIN_USER("
"USER_NAME TEXT,"
"GROUP_NAME TEXT,"
......@@ -49,7 +48,10 @@ void cta::catalogue::SqliteCatalogue::createDbSchema() {
"LAST_MODIFICATION_USER_NAME TEXT,"
"LAST_MODIFICATION_GROUP_NAME TEXT,"
"LAST_MODIFICATION_HOST_NAME TEXT,"
"LAST_MODIFICATION_TIME INTEGER);"
"LAST_MODIFICATION_TIME INTEGER,"
"PRIMARY KEY(USER_NAME)"
");"
"CREATE TABLE ADMIN_HOST("
"HOST_NAME TEXT,"
......@@ -63,7 +65,12 @@ void cta::catalogue::SqliteCatalogue::createDbSchema() {
"LAST_MODIFICATION_USER_NAME TEXT,"
"LAST_MODIFICATION_GROUP_NAME TEXT,"
"LAST_MODIFICATION_HOST_NAME TEXT,"
"LAST_MODIFICATION_TIME INTEGER);");
"LAST_MODIFICATION_TIME INTEGER,"
"PRIMARY KEY(HOST_NAME)"
");";
m_conn.enableForeignKeys();
m_conn.execNonQuery(sql);
}
//------------------------------------------------------------------------------
......@@ -228,9 +235,9 @@ std::list<cta::common::dataStructures::AdminUser> cta::catalogue::SqliteCatalogu
std::list<cta::common::dataStructures::AdminUser> admins;
const char *const sql =
"SELECT "
"USER_NAME AS USER_NAME,"
"GROUP_NAME AS GROUP_NAME,"
"COMMENT AS COMMENT,"
"USER_NAME AS USER_NAME,"
"GROUP_NAME AS GROUP_NAME,"
"COMMENT AS COMMENT,"
"CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"CREATION_LOG_GROUP_NAME AS CREATION_LOG_GROUP_NAME,"
......
......@@ -17,6 +17,7 @@
*/
#include "catalogue/SqliteCatalogue.hpp"
#include "common/exception/Exception.hpp"
#include <gtest/gtest.h>
#include <memory>
......@@ -173,6 +174,41 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminUser) {
}
}
TEST_F(cta_catalogue_SqliteCatalogueTest, createAdminUser_same_admin_twice) {
using namespace cta;
std::unique_ptr<catalogue::Catalogue> catalogue;
ASSERT_NO_THROW(catalogue.reset(new catalogue::SqliteCatalogue()));
ASSERT_NO_THROW(catalogue->createBootstrapAdminAndHostNoAuth(
m_cliSI, m_bootstrapAdminUI, m_bootstrapAdminSI.host, m_bootstrapComment));
{
std::list<common::dataStructures::AdminUser> admins;
ASSERT_NO_THROW(admins = catalogue->getAdminUsers(m_bootstrapAdminSI));
ASSERT_EQ(1, admins.size());
const common::dataStructures::AdminUser admin = admins.front();
ASSERT_EQ(m_bootstrapComment, admin.comment);
const common::dataStructures::EntryLog creationLog = admin.creationLog;
ASSERT_EQ(m_cliSI.user.name, creationLog.user.name);
ASSERT_EQ(m_cliSI.user.group, creationLog.user.group);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
admin.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string createAdminUserComment = "create admin user comment";
ASSERT_NO_THROW(catalogue->createAdminUser(m_bootstrapAdminSI, m_adminUI,
createAdminUserComment));
ASSERT_THROW(catalogue->createAdminUser(m_bootstrapAdminSI, m_adminUI,
createAdminUserComment), exception::Exception);
}
TEST_F(cta_catalogue_SqliteCatalogueTest, isAdmin_notAdmin) {
using namespace cta;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment