diff options
author | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-06-21 14:32:05 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@verizonmedia.com> | 2019-06-25 11:08:43 +0000 |
commit | 0ec1dddb0e75c235edfc68d72f4471ad186c3399 (patch) | |
tree | 254cdda75b06c8453a207933a8d556c1db90b997 /storage/src/tests/common/hostreporter | |
parent | a0d854b6a3fab6fe44b1164c071fc994b331c3bc (diff) |
Convert remaining CppUnit tests to GTest
Move base message sender stub out to common test module to
avoid artificial dependency from persistence tests to the
distributor tests.
Diffstat (limited to 'storage/src/tests/common/hostreporter')
4 files changed, 28 insertions, 46 deletions
diff --git a/storage/src/tests/common/hostreporter/CMakeLists.txt b/storage/src/tests/common/hostreporter/CMakeLists.txt index 7a4a23ba7aa..2fcb159cb08 100644 --- a/storage/src/tests/common/hostreporter/CMakeLists.txt +++ b/storage/src/tests/common/hostreporter/CMakeLists.txt @@ -1,9 +1,7 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. vespa_add_library(storage_testhostreporter TEST SOURCES - hostinfotest.cpp util.cpp - versionreportertest.cpp DEPENDS storage ) @@ -11,8 +9,11 @@ vespa_add_library(storage_testhostreporter TEST vespa_add_executable(storage_hostreporter_gtest_runner_app TEST SOURCES gtest_runner.cpp + hostinfotest.cpp + versionreportertest.cpp DEPENDS storage + storage_testhostreporter gtest ) diff --git a/storage/src/tests/common/hostreporter/hostinfotest.cpp b/storage/src/tests/common/hostreporter/hostinfotest.cpp index 418884c2a38..467149154ee 100644 --- a/storage/src/tests/common/hostreporter/hostinfotest.cpp +++ b/storage/src/tests/common/hostreporter/hostinfotest.cpp @@ -1,15 +1,18 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "util.h" #include <vespa/storage/common/hostreporter/hostinfo.h> #include <vespa/storage/common/hostreporter/hostreporter.h> -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/jsonstream.h> -#include "util.h" +#include <vespa/vespalib/gtest/gtest.h> + +using namespace ::testing; namespace storage { namespace { + using Object = vespalib::JsonStream::Object; using End = vespalib::JsonStream::End; using JsonFormat = vespalib::slime::JsonFormat; @@ -21,22 +24,10 @@ public: jsonreport << "dummy" << Object() << "foo" << "bar" << End(); } }; -} - -struct HostInfoReporterTest : public CppUnit::TestFixture -{ - void testHostInfoReporter(); - CPPUNIT_TEST_SUITE(HostInfoReporterTest); - CPPUNIT_TEST(testHostInfoReporter); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(HostInfoReporterTest); +} -void -HostInfoReporterTest::testHostInfoReporter() -{ +TEST(HostInfoReporterTest, host_info_reporter) { HostInfo hostinfo; DummyReporter dummyReporter; hostinfo.registerReporter(&dummyReporter); @@ -50,8 +41,8 @@ HostInfoReporterTest::testHostInfoReporter() std::string jsonData = json.str(); vespalib::Slime slime; JsonFormat::decode(Memory(jsonData), slime); - CPPUNIT_ASSERT(slime.get()["dummy"]["foo"].asString() == "bar"); - CPPUNIT_ASSERT(!slime.get()["vtag"]["version"].asString().make_string().empty()); + EXPECT_EQ(slime.get()["dummy"]["foo"].asString(), "bar"); + EXPECT_FALSE(slime.get()["vtag"]["version"].asString().make_string().empty()); } -} // storage +} // storage diff --git a/storage/src/tests/common/hostreporter/util.cpp b/storage/src/tests/common/hostreporter/util.cpp index e0563a431e6..02e66b1dcc7 100644 --- a/storage/src/tests/common/hostreporter/util.cpp +++ b/storage/src/tests/common/hostreporter/util.cpp @@ -2,12 +2,11 @@ #include "util.h" #include <vespa/storage/common/hostreporter/hostreporter.h> #include <vespa/vespalib/data/slime/slime.h> -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/util/jsonstream.h> #include <vespa/vespalib/stllike/asciistream.h> -namespace storage { -namespace util { +namespace storage::util { + namespace { using Object = vespalib::JsonStream::Object; using End = vespalib::JsonStream::End; @@ -27,8 +26,8 @@ reporterToSlime(HostReporter &hostReporter, vespalib::Slime &slime) { size_t parsed = JsonFormat::decode(Memory(jsonData), slime); if (parsed == 0) { - CPPUNIT_FAIL("jsonData is not json:\n" + jsonData); + throw std::runtime_error("jsonData is not json:\n" + jsonData); } } -} + } diff --git a/storage/src/tests/common/hostreporter/versionreportertest.cpp b/storage/src/tests/common/hostreporter/versionreportertest.cpp index dd58493f540..ee8fe2a5ff3 100644 --- a/storage/src/tests/common/hostreporter/versionreportertest.cpp +++ b/storage/src/tests/common/hostreporter/versionreportertest.cpp @@ -1,38 +1,29 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/log/log.h> + +#include "util.h" #include <vespa/storage/common/hostreporter/versionreporter.h> -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/util/jsonstream.h> -#include "util.h" +#include <vespa/vespalib/gtest/gtest.h> +#include <gmock/gmock.h> -LOG_SETUP(".test.versionreporter"); +using namespace ::testing; namespace storage { namespace { + using Object = vespalib::JsonStream::Object; using End = vespalib::JsonStream::End; -} -struct VersionReporterTest : public CppUnit::TestFixture -{ - void testVersionReporter(); - - CPPUNIT_TEST_SUITE(VersionReporterTest); - CPPUNIT_TEST(testVersionReporter); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(VersionReporterTest); +} -void -VersionReporterTest::testVersionReporter() -{ +TEST(VersionReporterTest, version_reporter) { VersionReporter versionReporter; vespalib::Slime slime; util::reporterToSlime(versionReporter, slime); std::string version = slime.get()["vtag"]["version"].asString().make_string().c_str(); - CPPUNIT_ASSERT(version.length() > 2); - CPPUNIT_ASSERT(version.find(".") > 0); + EXPECT_GT(version.size(), 2); + EXPECT_THAT(version, HasSubstr(".")); } + } // storage |