summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2024-03-11 13:48:20 +0100
committerTor Egge <Tor.Egge@online.no>2024-03-11 13:48:20 +0100
commit950e5c2545861fa63f49781e7d058495966ee93f (patch)
treeeb2e18b6b77ff2ace8ffda6e45a1f850fcb10872
parent8e288413b5a3b77daa6de4245d1c690a1b557fa0 (diff)
Rewrite messagebus config agent unit test to gtest.
-rw-r--r--messagebus/src/tests/configagent/CMakeLists.txt1
-rw-r--r--messagebus/src/tests/configagent/configagent.cpp137
2 files changed, 72 insertions, 66 deletions
diff --git a/messagebus/src/tests/configagent/CMakeLists.txt b/messagebus/src/tests/configagent/CMakeLists.txt
index 9cc9eacbe1c..9b07222fc74 100644
--- a/messagebus/src/tests/configagent/CMakeLists.txt
+++ b/messagebus/src/tests/configagent/CMakeLists.txt
@@ -5,5 +5,6 @@ vespa_add_executable(messagebus_configagent_test_app TEST
DEPENDS
messagebus_messagebus-test
messagebus
+ GTest::gtest
)
vespa_add_test(NAME messagebus_configagent_test_app COMMAND messagebus_configagent_test_app)
diff --git a/messagebus/src/tests/configagent/configagent.cpp b/messagebus/src/tests/configagent/configagent.cpp
index f93bfd6c841..e8cab1e679a 100644
--- a/messagebus/src/tests/configagent/configagent.cpp
+++ b/messagebus/src/tests/configagent/configagent.cpp
@@ -1,109 +1,113 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/messagebus/configagent.h>
#include <vespa/messagebus/iconfighandler.h>
#include <vespa/messagebus/routing/routingspec.h>
#include <vespa/messagebus/config-messagebus.h>
#include <vespa/config/print/fileconfigreader.hpp>
+#include <vespa/vespalib/gtest/gtest.h>
+#include <vespa/vespalib/testkit/test_path.h>
using namespace mbus;
using namespace messagebus;
using namespace config;
-class Test : public vespalib::TestApp, public IConfigHandler {
-private:
+class ConfigAgentTest : public testing::Test, public IConfigHandler {
+protected:
RoutingSpec _spec;
+ ConfigAgentTest();
+ ~ConfigAgentTest() override;
bool checkHalf();
bool checkFull();
- bool checkTables(uint32_t numTables);
-
-public:
- ~Test() override;
- int Main() override;
+ void checkTables(uint32_t numTables, bool& success);
bool setupRouting(RoutingSpec spec) override;
};
-Test::~Test() = default;
+ConfigAgentTest::ConfigAgentTest()
+ : testing::Test(),
+ IConfigHandler(),
+ _spec()
+{
+}
-TEST_APPHOOK(Test);
+ConfigAgentTest::~ConfigAgentTest() = default;
bool
-Test::setupRouting(RoutingSpec spec)
+ConfigAgentTest::setupRouting(RoutingSpec spec)
{
_spec = std::move(spec);
return true;
}
-bool
-Test::checkTables(uint32_t numTables)
+void
+ConfigAgentTest::checkTables(uint32_t numTables, bool& success)
{
- if (!EXPECT_EQUAL(numTables, _spec.getNumTables())) return false;
+ ASSERT_EQ(numTables, _spec.getNumTables());
if (numTables > 0) {
- if (!EXPECT_EQUAL("foo", _spec.getTable(0).getProtocol())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(0).getNumHops())) return false;
- if (!EXPECT_EQUAL("foo-h1", _spec.getTable(0).getHop(0).getName())) return false;
- if (!EXPECT_EQUAL("foo-h1-sel", _spec.getTable(0).getHop(0).getSelector())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(0).getHop(0).getNumRecipients())) return false;
- if (!EXPECT_EQUAL("foo-h1-r1", _spec.getTable(0).getHop(0).getRecipient(0))) return false;
- if (!EXPECT_EQUAL("foo-h1-r2", _spec.getTable(0).getHop(0).getRecipient(1))) return false;
- if (!EXPECT_EQUAL(true, _spec.getTable(0).getHop(0).getIgnoreResult())) return false;
- if (!EXPECT_EQUAL("foo-h2", _spec.getTable(0).getHop(1).getName())) return false;
- if (!EXPECT_EQUAL("foo-h2-sel", _spec.getTable(0).getHop(1).getSelector())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(0).getHop(1).getNumRecipients())) return false;
- if (!EXPECT_EQUAL("foo-h2-r1", _spec.getTable(0).getHop(1).getRecipient(0))) return false;
- if (!EXPECT_EQUAL("foo-h2-r2", _spec.getTable(0).getHop(1).getRecipient(1))) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(0).getNumRoutes())) return false;
- if (!EXPECT_EQUAL("foo-r1", _spec.getTable(0).getRoute(0).getName())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(0).getRoute(0).getNumHops())) return false;
- if (!EXPECT_EQUAL("foo-h1", _spec.getTable(0).getRoute(0).getHop(0))) return false;
- if (!EXPECT_EQUAL("foo-h2", _spec.getTable(0).getRoute(0).getHop(1))) return false;
- if (!EXPECT_EQUAL("foo-r2", _spec.getTable(0).getRoute(1).getName())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(0).getRoute(1).getNumHops())) return false;
- if (!EXPECT_EQUAL("foo-h2", _spec.getTable(0).getRoute(1).getHop(0))) return false;
- if (!EXPECT_EQUAL("foo-h1", _spec.getTable(0).getRoute(1).getHop(1))) return false;
+ ASSERT_EQ("foo", _spec.getTable(0).getProtocol());
+ ASSERT_EQ(2u, _spec.getTable(0).getNumHops());
+ ASSERT_EQ("foo-h1", _spec.getTable(0).getHop(0).getName());
+ ASSERT_EQ("foo-h1-sel", _spec.getTable(0).getHop(0).getSelector());
+ ASSERT_EQ(2u, _spec.getTable(0).getHop(0).getNumRecipients());
+ ASSERT_EQ("foo-h1-r1", _spec.getTable(0).getHop(0).getRecipient(0));
+ ASSERT_EQ("foo-h1-r2", _spec.getTable(0).getHop(0).getRecipient(1));
+ ASSERT_EQ(true, _spec.getTable(0).getHop(0).getIgnoreResult());
+ ASSERT_EQ("foo-h2", _spec.getTable(0).getHop(1).getName());
+ ASSERT_EQ("foo-h2-sel", _spec.getTable(0).getHop(1).getSelector());
+ ASSERT_EQ(2u, _spec.getTable(0).getHop(1).getNumRecipients());
+ ASSERT_EQ("foo-h2-r1", _spec.getTable(0).getHop(1).getRecipient(0));
+ ASSERT_EQ("foo-h2-r2", _spec.getTable(0).getHop(1).getRecipient(1));
+ ASSERT_EQ(2u, _spec.getTable(0).getNumRoutes());
+ ASSERT_EQ("foo-r1", _spec.getTable(0).getRoute(0).getName());
+ ASSERT_EQ(2u, _spec.getTable(0).getRoute(0).getNumHops());
+ ASSERT_EQ("foo-h1", _spec.getTable(0).getRoute(0).getHop(0));
+ ASSERT_EQ("foo-h2", _spec.getTable(0).getRoute(0).getHop(1));
+ ASSERT_EQ("foo-r2", _spec.getTable(0).getRoute(1).getName());
+ ASSERT_EQ(2u, _spec.getTable(0).getRoute(1).getNumHops());
+ ASSERT_EQ("foo-h2", _spec.getTable(0).getRoute(1).getHop(0));
+ ASSERT_EQ("foo-h1", _spec.getTable(0).getRoute(1).getHop(1));
}
if (numTables > 1) {
- if (!EXPECT_EQUAL("bar", _spec.getTable(1).getProtocol())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(1).getNumHops())) return false;
- if (!EXPECT_EQUAL("bar-h1", _spec.getTable(1).getHop(0).getName())) return false;
- if (!EXPECT_EQUAL("bar-h1-sel", _spec.getTable(1).getHop(0).getSelector())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(1).getHop(0).getNumRecipients())) return false;
- if (!EXPECT_EQUAL("bar-h1-r1", _spec.getTable(1).getHop(0).getRecipient(0))) return false;
- if (!EXPECT_EQUAL("bar-h1-r2", _spec.getTable(1).getHop(0).getRecipient(1))) return false;
- if (!EXPECT_EQUAL("bar-h2", _spec.getTable(1).getHop(1).getName())) return false;
- if (!EXPECT_EQUAL("bar-h2-sel", _spec.getTable(1).getHop(1).getSelector())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(1).getHop(1).getNumRecipients())) return false;
- if (!EXPECT_EQUAL("bar-h2-r1", _spec.getTable(1).getHop(1).getRecipient(0))) return false;
- if (!EXPECT_EQUAL("bar-h2-r2", _spec.getTable(1).getHop(1).getRecipient(1))) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(1).getNumRoutes())) return false;
- if (!EXPECT_EQUAL("bar-r1", _spec.getTable(1).getRoute(0).getName())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(1).getRoute(0).getNumHops())) return false;
- if (!EXPECT_EQUAL("bar-h1", _spec.getTable(1).getRoute(0).getHop(0))) return false;
- if (!EXPECT_EQUAL("bar-h2", _spec.getTable(1).getRoute(0).getHop(1))) return false;
- if (!EXPECT_EQUAL("bar-r2", _spec.getTable(1).getRoute(1).getName())) return false;
- if (!EXPECT_EQUAL(2u, _spec.getTable(1).getRoute(1).getNumHops())) return false;
- if (!EXPECT_EQUAL("bar-h2", _spec.getTable(1).getRoute(1).getHop(0))) return false;
- if (!EXPECT_EQUAL("bar-h1", _spec.getTable(1).getRoute(1).getHop(1))) return false;
+ ASSERT_EQ("bar", _spec.getTable(1).getProtocol());
+ ASSERT_EQ(2u, _spec.getTable(1).getNumHops());
+ ASSERT_EQ("bar-h1", _spec.getTable(1).getHop(0).getName());
+ ASSERT_EQ("bar-h1-sel", _spec.getTable(1).getHop(0).getSelector());
+ ASSERT_EQ(2u, _spec.getTable(1).getHop(0).getNumRecipients());
+ ASSERT_EQ("bar-h1-r1", _spec.getTable(1).getHop(0).getRecipient(0));
+ ASSERT_EQ("bar-h1-r2", _spec.getTable(1).getHop(0).getRecipient(1));
+ ASSERT_EQ("bar-h2", _spec.getTable(1).getHop(1).getName());
+ ASSERT_EQ("bar-h2-sel", _spec.getTable(1).getHop(1).getSelector());
+ ASSERT_EQ(2u, _spec.getTable(1).getHop(1).getNumRecipients());
+ ASSERT_EQ("bar-h2-r1", _spec.getTable(1).getHop(1).getRecipient(0));
+ ASSERT_EQ("bar-h2-r2", _spec.getTable(1).getHop(1).getRecipient(1));
+ ASSERT_EQ(2u, _spec.getTable(1).getNumRoutes());
+ ASSERT_EQ("bar-r1", _spec.getTable(1).getRoute(0).getName());
+ ASSERT_EQ(2u, _spec.getTable(1).getRoute(0).getNumHops());
+ ASSERT_EQ("bar-h1", _spec.getTable(1).getRoute(0).getHop(0));
+ ASSERT_EQ("bar-h2", _spec.getTable(1).getRoute(0).getHop(1));
+ ASSERT_EQ("bar-r2", _spec.getTable(1).getRoute(1).getName());
+ ASSERT_EQ(2u, _spec.getTable(1).getRoute(1).getNumHops());
+ ASSERT_EQ("bar-h2", _spec.getTable(1).getRoute(1).getHop(0));
+ ASSERT_EQ("bar-h1", _spec.getTable(1).getRoute(1).getHop(1));
}
- return true;
+ success = true;
}
bool
-Test::checkHalf()
+ConfigAgentTest::checkHalf()
{
- return _spec.getNumTables() == 1 && EXPECT_TRUE(checkTables(1));
+ bool success = false;
+ return _spec.getNumTables() == 1 && (checkTables(1, success), success);
}
bool
-Test::checkFull()
+ConfigAgentTest::checkFull()
{
- return _spec.getNumTables() == 2 && EXPECT_TRUE(checkTables(2));
+ bool success = false;
+ return _spec.getNumTables() == 2 && (checkTables(2, success), success);
}
-int
-Test::Main()
+TEST_F(ConfigAgentTest, test_config_agent)
{
- TEST_INIT("configagent_test");
EXPECT_TRUE(!checkHalf());
EXPECT_TRUE(!checkFull());
ConfigAgent agent(*this);
@@ -118,5 +122,6 @@ Test::Main()
agent.configure(FileConfigReader<MessagebusConfig>(TEST_PATH("full.cfg")).read());
EXPECT_TRUE(checkFull());
EXPECT_TRUE(!checkHalf());
- TEST_DONE();
}
+
+GTEST_MAIN_RUN_ALL_TESTS()