diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-22 22:14:31 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-22 22:14:31 +0100 |
commit | db00a9699e3b12e5f1b79b55a4fd35c4e1dee163 (patch) | |
tree | 1b706ea330f7399f7c0c5cb4dc43b5f7f7ba4815 /unittests | |
parent | Unline git helpers and throw NetFS exceptions (diff) | |
download | netfs-gitfs-db00a9699e3b12e5f1b79b55a4fd35c4e1dee163.tar.bz2 netfs-gitfs-db00a9699e3b12e5f1b79b55a4fd35c4e1dee163.tar.xz netfs-gitfs-db00a9699e3b12e5f1b79b55a4fd35c4e1dee163.zip |
Replace hard-coded test values with properties
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Jamfile.jam | 12 | ||||
-rw-r--r-- | unittests/config.cpp | 81 | ||||
-rw-r--r-- | unittests/core.cpp | 6 | ||||
-rw-r--r-- | unittests/mockDefs.cpp | 11 | ||||
-rw-r--r-- | unittests/service.cpp | 56 |
5 files changed, 153 insertions, 13 deletions
diff --git a/unittests/Jamfile.jam b/unittests/Jamfile.jam index a44275f..830fd25 100644 --- a/unittests/Jamfile.jam +++ b/unittests/Jamfile.jam @@ -3,7 +3,7 @@ import testing ; lib boost_utf : : <name>boost_unit_test_framework ; lib dryice : : : : <library>..//icetray ; -path-constant me : . ; +path-constant gitdir : ../.git ; lib common : mockDefs.cpp @@ -12,17 +12,17 @@ lib common : <library>../src//gitfs++11 <library>..//adhocutil <library>boost_utf - <define>ROOT=\"$(me)\" + <define>ROOT=\"$(gitdir)\" : : <library>dryice <library>../src//gitfs++11 <library>boost_utf - <define>ROOT=\"$(me)\" + <define>ROOT=\"$(gitdir)\" <define>BOOST_TEST_DYN_LINK ; -run core.cpp : : : - <library>common - ; +run config.cpp : : : <library>common ; +run core.cpp : : : <library>common ; +run service.cpp : : : <library>common ; diff --git a/unittests/config.cpp b/unittests/config.cpp new file mode 100644 index 0000000..0cfc22c --- /dev/null +++ b/unittests/config.cpp @@ -0,0 +1,81 @@ +#define BOOST_TEST_MODULE GitFS_Config +#include <boost/test/unit_test.hpp> +#include <boost/test/data/test_case.hpp> + +#include <definedDirs.h> +#include <compileTimeFormatter.h> +#include "mockDefs.h" + +using namespace GitFS; +using namespace GitFS::Test; +using namespace AdHoc::literals; + +namespace btdata = boost::unit_test::data; + +class IdsIce : public IceTray::DryIce { + public: + IdsIce(const char * uid, const char * gid) : IceTray::DryIce({ + "--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()), + "--GitFS.testrepo.authkey=%?"_fmt("testauth"), + "--GitFS.testrepo.gid=%?"_fmt(gid), + "--GitFS.testrepo.uid=%?"_fmt(uid), + "--GitFS.testrepo.commit=7a0ccb40084c3ab31d9856e7f689c0514c28c930", + }) + {} +}; + +const auto USERS = btdata::make({ "root", "gituser", "www" }); +const auto GROUPS = btdata::make({ "root", "gitgroup", "www" }); +const auto DIRS = btdata::make({ "/", "/src", "/unittests/fixtures" }); +const auto FILES = btdata::make({ + "/Jamroot.jam", "/src/repo.cpp", "/unittests/fixtures/executable" }); +const auto LINKS = btdata::make({ "/unittests/fixtures/symlink" }); + +BOOST_DATA_TEST_CASE(uid_gid_override_getattr, + USERS * GROUPS * (DIRS + FILES + LINKS), + uid, gid, path) +{ + IdsIce s(uid, gid); + VolumeClient c; + BOOST_CHECK_NO_THROW(c.s->ice_ping()); + + auto attr = c.v->getattr(c.env, path); + BOOST_CHECK_EQUAL(attr.uid, uid); + BOOST_CHECK_EQUAL(attr.gid, gid); +} + +BOOST_DATA_TEST_CASE(uid_gid_override_fgetattr, + USERS * GROUPS * FILES, + uid, gid, path) +{ + IdsIce s(uid, gid); + VolumeClient c; + BOOST_CHECK_NO_THROW(c.s->ice_ping()); + + auto file = c.v->open(c.env, path, {}); + auto attr = file->fgetattr(c.env); + BOOST_CHECK_EQUAL(attr.uid, uid); + BOOST_CHECK_EQUAL(attr.gid, gid); + file->close(); +} + +BOOST_DATA_TEST_CASE(uid_gid_override_list, + USERS * GROUPS * DIRS, + uid, gid, path) +{ + IdsIce s(uid, gid); + VolumeClient c; + BOOST_CHECK_NO_THROW(c.s->ice_ping()); + + auto dir = c.v->opendir(c.env, path); + auto dir2 = Ice::checkedCast<NetFS::DirectoryV2Prx>(dir); + for (const auto & dirent : dir2->listdir()) { + BOOST_TEST_CONTEXT(dirent.first) { + BOOST_CHECK_EQUAL(dirent.second.uid, uid); + BOOST_CHECK_EQUAL(dirent.second.gid, gid); + } + } + dir->close(); +} + + diff --git a/unittests/core.cpp b/unittests/core.cpp index 78be8d7..6eef46a 100644 --- a/unittests/core.cpp +++ b/unittests/core.cpp @@ -43,12 +43,6 @@ namespace std { BOOST_TEST_GLOBAL_FIXTURE(Service); -BOOST_FIXTURE_TEST_SUITE(client, Client); - - // TODO - -BOOST_AUTO_TEST_SUITE_END(); - BOOST_FIXTURE_TEST_SUITE(volume, VolumeClient); BOOST_AUTO_TEST_CASE( unsupported_rofs_ops ) diff --git a/unittests/mockDefs.cpp b/unittests/mockDefs.cpp index 6d884d9..dff4cbc 100644 --- a/unittests/mockDefs.cpp +++ b/unittests/mockDefs.cpp @@ -1,7 +1,16 @@ #include <boost/test/test_tools.hpp> +#include <compileTimeFormatter.h> +#include <definedDirs.h> #include "mockDefs.h" -GitFS::Test::Service::Service() +using namespace AdHoc::literals; + +GitFS::Test::Service::Service() : + IceTray::DryIce({ + "--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()), + "--GitFS.testrepo.authkey=testauth", + "--GitFS.testrepo.commit=7a0ccb40084c3ab31d9856e7f689c0514c28c930", + }) { } diff --git a/unittests/service.cpp b/unittests/service.cpp new file mode 100644 index 0000000..aaa9d85 --- /dev/null +++ b/unittests/service.cpp @@ -0,0 +1,56 @@ +#define BOOST_TEST_MODULE GitFS_Service +#include <boost/test/unit_test.hpp> +#include <boost/test/data/test_case.hpp> + +#include <definedDirs.h> +#include <compileTimeFormatter.h> +#include "mockDefs.h" + +using namespace GitFS; +using namespace GitFS::Test; +using namespace AdHoc::literals; + +namespace btdata = boost::unit_test::data; + +BOOST_DATA_TEST_CASE(no_repos, + btdata::make({ "", "testrepo", "no repo" }) * + btdata::make({ "", "testauth", "badkey" }), + repo, key) +{ + IceTray::DryIce s; + Client c; + BOOST_CHECK_NO_THROW(c.s->ice_ping()); + + BOOST_CHECK_THROW(c.s->connect(repo, key), NetFS::ConfigError); +} + +BOOST_DATA_TEST_CASE(badauth, + btdata::make({ "", "testAuth", "badkey" }), + key) +{ + IceTray::DryIce s({ + "--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()), + "--GitFS.testrepo.authkey=testauth", + "--GitFS.testrepo.commit=7a0ccb40084c3ab31d9856e7f689c0514c28c930", + }); + Client c; + BOOST_CHECK_NO_THROW(c.s->ice_ping()); + + BOOST_CHECK_THROW(c.s->connect("testrepo", key), NetFS::AuthError); +} + +BOOST_AUTO_TEST_CASE(missing_repo) +{ + IceTray::DryIce s({ + "--GitFS.missing.gitdir=/not/here", + "--GitFS.missing.commit=7a0ccb40084c3ab31d9856e7f689c0514c28c930", + "--GitFS.testrepo.gitdir=%?"_fmt(rootDir.string()), + "--GitFS.testrepo.commit=7a0ccb40084c3ab31d9856e7f689c0514c28c931", + }); + Client c; + BOOST_CHECK_NO_THROW(c.s->ice_ping()); + + BOOST_CHECK_THROW(c.s->connect("missing", {}), NetFS::ConfigError); + BOOST_CHECK_THROW(c.s->connect("testrepo", {}), NetFS::ConfigError); +} + |