From ac671e6105fb555008fac2d5cdeda5311bdb342f Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Fri, 24 Feb 2017 17:35:08 +0100 Subject: [PATCH] [5107] Two unit-tests implemented for CtrlAgentCommandMgr --- src/bin/agent/ctrl_agent_command_mgr.h | 4 +- .../tests/ctrl_agent_command_mgr_unittest.cc | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/bin/agent/ctrl_agent_command_mgr.h b/src/bin/agent/ctrl_agent_command_mgr.h index 573c575ddc..03de1b12a9 100644 --- a/src/bin/agent/ctrl_agent_command_mgr.h +++ b/src/bin/agent/ctrl_agent_command_mgr.h @@ -34,8 +34,6 @@ public: /// @brief Returns sole instance of the Command Manager. static CtrlAgentCommandMgr& instance(); -private: - /// @brief Handles the command having a given name and arguments. /// /// This method extends the base implementation with the ability to forward @@ -54,7 +52,7 @@ private: handleCommand(const std::string& cmd_name, const isc::data::ConstElementPtr& params); - +private: /// @brief Private constructor. /// /// The instance should be created using @ref CtrlAgentCommandMgr::instance, diff --git a/src/bin/agent/tests/ctrl_agent_command_mgr_unittest.cc b/src/bin/agent/tests/ctrl_agent_command_mgr_unittest.cc index df0db24eba..e345312ff6 100644 --- a/src/bin/agent/tests/ctrl_agent_command_mgr_unittest.cc +++ b/src/bin/agent/tests/ctrl_agent_command_mgr_unittest.cc @@ -6,9 +6,11 @@ #include #include +#include #include using namespace isc::agent; +using namespace isc::data; namespace { @@ -23,16 +25,55 @@ public: /// @brief Constructor. /// /// Deregisters all commands except 'list-commands'. - CtrlAgentCommandMgrTest() { - CtrlAgentCommandMgr::instance().deregisterAll(); + CtrlAgentCommandMgrTest() + : mgr_(CtrlAgentCommandMgr::instance()) { + mgr_.deregisterAll(); } /// @brief Destructor. /// /// Deregisters all commands except 'list-commands'. virtual ~CtrlAgentCommandMgrTest() { - CtrlAgentCommandMgr::instance().deregisterAll(); + mgr_.deregisterAll(); } + + /// @brief Verifies received answer + /// + /// @todo Add better checks for failure cases and for + /// verification of the response parameters. + /// + /// @param answer answer to be verified + /// @param expected_code code expected to be returned in the answer + void checkAnswer(ConstElementPtr answer, int expected_code) { + int status_code; + isc::config::parseAnswer(status_code, answer); + EXPECT_EQ(expected_code, status_code); + } + + /// @brief a convenience reference to control agent command manager + CtrlAgentCommandMgr& mgr_; +}; + +/// Just a basic test checking that non-existent command is handled +/// properly. +TEST_F(CtrlAgentCommandMgrTest, bogus) { + + ConstElementPtr answer; + + EXPECT_NO_THROW(answer = mgr_.handleCommand("fish-and-chips-please", + ConstElementPtr())); + checkAnswer(answer, isc::config::CONTROL_RESULT_ERROR); }; +/// Just a basic test checking that 'list-commands' is supported. +TEST_F(CtrlAgentCommandMgrTest, listCommands) { + + ConstElementPtr answer; + + EXPECT_NO_THROW(answer = mgr_.handleCommand("list-commands", + ConstElementPtr())); + checkAnswer(answer, isc::config::CONTROL_RESULT_ERROR); +}; + + } -- 2.47.3