summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/unittests/mockGlacier.cpp29
-rw-r--r--netfs/unittests/mockGlacier.h19
-rw-r--r--netfs/unittests/testGlacier.cpp35
3 files changed, 59 insertions, 24 deletions
diff --git a/netfs/unittests/mockGlacier.cpp b/netfs/unittests/mockGlacier.cpp
new file mode 100644
index 0000000..f1e8e72
--- /dev/null
+++ b/netfs/unittests/mockGlacier.cpp
@@ -0,0 +1,29 @@
+#include "mockGlacier.h"
+#include <boost/test/test_tools.hpp>
+#include <csignal>
+#include <sys/file.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+
+Glacier::Glacier() : lockdir(open("/tmp", O_DIRECTORY))
+{
+ BOOST_REQUIRE_GE(lockdir, 0);
+ BOOST_REQUIRE_EQUAL(0, flock(lockdir, LOCK_EX));
+ if (glacier = fork(); glacier == 0) {
+ prctl(PR_SET_PDEATHSIG, SIGINT);
+ execl("/usr/bin/glacier2router", "--Glacier2.Client.Endpoints=tcp -p 14063",
+ "--Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier", nullptr);
+ BOOST_FAIL("Should never get here");
+ }
+ BOOST_REQUIRE_GT(glacier, 0);
+ sleep(1);
+}
+
+Glacier::~Glacier()
+{
+ BOOST_CHECK_EQUAL(0, kill(glacier, SIGINT));
+ int status {};
+ BOOST_CHECK_EQUAL(glacier, waitpid(glacier, &status, 0));
+ BOOST_CHECK_EQUAL(0, status);
+ BOOST_CHECK_EQUAL(0, close(lockdir));
+}
diff --git a/netfs/unittests/mockGlacier.h b/netfs/unittests/mockGlacier.h
new file mode 100644
index 0000000..007715d
--- /dev/null
+++ b/netfs/unittests/mockGlacier.h
@@ -0,0 +1,19 @@
+#ifndef MOCKGLACIER_H
+#define MOCKGLACIER_H
+
+#include <c++11Helpers.h>
+#include <sys/types.h>
+#include <visibility.h>
+
+class DLL_PUBLIC Glacier {
+public:
+ Glacier();
+ ~Glacier();
+ SPECIAL_MEMBERS_DELETE(Glacier);
+
+private:
+ const int lockdir;
+ pid_t glacier;
+};
+
+#endif
diff --git a/netfs/unittests/testGlacier.cpp b/netfs/unittests/testGlacier.cpp
index 5467c41..afe3475 100644
--- a/netfs/unittests/testGlacier.cpp
+++ b/netfs/unittests/testGlacier.cpp
@@ -1,35 +1,22 @@
#define BOOST_TEST_MODULE TestNetFSGlacier
+#include <boost/test/unit_test.hpp>
+
#include "mockDaemon.h"
#include "mockFuse.h"
-#include <boost/scope_exit.hpp>
-#include <boost/test/unit_test.hpp>
+#include "mockGlacier.h"
#include <definedDirs.h>
const std::string testEndpoint("tcp -h localhost -p 12013");
-#define PID "/tmp/glacier.pid"
+
+BOOST_TEST_GLOBAL_FIXTURE(Glacier);
BOOST_AUTO_TEST_CASE(withRouter)
{
- std::filesystem::remove(PID);
- BOOST_REQUIRE_EQUAL(0,
- system("flock /tmp/glacier.lock /usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 14063' "
- "--Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile " PID));
- sleep(1);
-
- BOOST_SCOPE_EXIT(void)
- {
- BOOST_REQUIRE_EQUAL(0, system("kill $(cat " PID ")"));
- std::filesystem::remove(PID);
- }
- BOOST_SCOPE_EXIT_END;
-
- {
- MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
- FuseMockHost fuse(testEndpoint,
- {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string(),
- "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063"});
+ MockDaemonHost daemon(testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()});
+ FuseMockHost fuse(testEndpoint,
+ {(rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string(),
+ "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063"});
- struct statvfs s { };
- BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s));
- }
+ struct statvfs s { };
+ BOOST_CHECK_EQUAL(0, fuse.fuse->statfs("/", &s));
}