From 50dff4f5e67381f53095c071bd8be6d36a882f1d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 19 Jul 2015 19:45:51 +0100 Subject: Start mock daemons with a real configuration file that has specific parts replaced at run-time --- netfs/unittests/Jamfile.jam | 6 +++--- netfs/unittests/defaultDaemon.xml | 11 +++++++++++ netfs/unittests/mockDaemon.cpp | 18 +++++++++--------- netfs/unittests/testCore.cpp | 4 +++- netfs/unittests/testEdgeCases.cpp | 4 +++- netfs/unittests/testGlacier.cpp | 4 +++- 6 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 netfs/unittests/defaultDaemon.xml diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index 79f77e3..8811d27 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -27,21 +27,21 @@ lib testMocks : run testCore.cpp - : : : + : : defaultDaemon.xml : BOOST_TEST_DYN_LINK boost_utf testMocks : testCore ; run testGlacier.cpp - : : : + : : defaultDaemon.xml : BOOST_TEST_DYN_LINK boost_utf testMocks : testGlacier ; run testEdgeCases.cpp - : : : + : : defaultDaemon.xml : BOOST_TEST_DYN_LINK boost_utf testMocks diff --git a/netfs/unittests/defaultDaemon.xml b/netfs/unittests/defaultDaemon.xml new file mode 100644 index 0000000..76711cc --- /dev/null +++ b/netfs/unittests/defaultDaemon.xml @@ -0,0 +1,11 @@ + + + + + testvol + + /overridden + + + + diff --git a/netfs/unittests/mockDaemon.cpp b/netfs/unittests/mockDaemon.cpp index 4a735e8..fa8c1a0 100644 --- a/netfs/unittests/mockDaemon.cpp +++ b/netfs/unittests/mockDaemon.cpp @@ -17,15 +17,14 @@ MockDaemon::MockDaemon(const std::string & ep) : } NetFS::Daemon::ConfigurationPtr -MockDaemon::ReadConfiguration(const boost::filesystem::path &) const +MockDaemon::ReadConfiguration(const boost::filesystem::path & path) const { - return new NetFS::Daemon::Configuration( - { - { "testvol", new NetFS::Daemon::Export(TestExportRoot.string()) } - }, - { - { "unittest", new NetFS::Daemon::Host(testEndpoint) } - }); + auto c = NetFSDaemon::ReadConfiguration(path); + for(auto e : c->Exports) { + e.second->RootPath = TestExportRoot.string(); + } + c->Hosts.insert({ "unittest", new NetFS::Daemon::Host(testEndpoint) }); + return c; } MockDaemonHost::MockDaemonHost(const std::string & ep, const Ice::StringSeq & ps) : @@ -59,7 +58,8 @@ MockDaemonHost::stop() void MockDaemonHost::start() { - ic = Ice::initialize(params); + ic = Ice::initialize(); + ic->getProperties()->parseCommandLineOptions("NetFSD", params); ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); daemon = new MockDaemon(testEndpoint); daemon->start("NetFSDaemonAdapter", ic, {}); diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 75d55a4..af03ed3 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -21,7 +21,9 @@ char * defaultFuseArgv[] = { class Core { public: Core() : - daemonHost(testEndpoint), + daemonHost(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }), fuseHost(testEndpoint, 2, defaultFuseArgv), ic(daemonHost.ic), fuse(fuseHost.fuse) diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp index afa2338..3955e73 100644 --- a/netfs/unittests/testEdgeCases.cpp +++ b/netfs/unittests/testEdgeCases.cpp @@ -20,7 +20,9 @@ char * defaultFuseArgv[] = { BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) { - MockDaemonHost daemon(testEndpoint); + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); FuseMockHost fuse(testEndpoint, 2, defaultFuseArgv); struct statvfs s; diff --git a/netfs/unittests/testGlacier.cpp b/netfs/unittests/testGlacier.cpp index 17f892a..abe8a1e 100644 --- a/netfs/unittests/testGlacier.cpp +++ b/netfs/unittests/testGlacier.cpp @@ -31,7 +31,9 @@ BOOST_AUTO_TEST_CASE ( withRouter ) strdup("--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 4063") }; - MockDaemonHost daemon(testEndpoint); + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (RootDir / "defaultDaemon.xml").string() + }); FuseMockHost fuse(testEndpoint, 3, glacierFuseArgv); struct statvfs s; -- cgit v1.2.3