From db00a9699e3b12e5f1b79b55a4fd35c4e1dee163 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Jul 2019 22:14:31 +0100 Subject: Replace hard-coded test values with properties --- unittests/Jamfile.jam | 12 ++++---- unittests/config.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ unittests/core.cpp | 6 ---- unittests/mockDefs.cpp | 11 ++++++- unittests/service.cpp | 56 ++++++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 unittests/config.cpp create mode 100644 unittests/service.cpp (limited to 'unittests') 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 : : boost_unit_test_framework ; lib dryice : : : : ..//icetray ; -path-constant me : . ; +path-constant gitdir : ../.git ; lib common : mockDefs.cpp @@ -12,17 +12,17 @@ lib common : ../src//gitfs++11 ..//adhocutil boost_utf - ROOT=\"$(me)\" + ROOT=\"$(gitdir)\" : : dryice ../src//gitfs++11 boost_utf - ROOT=\"$(me)\" + ROOT=\"$(gitdir)\" BOOST_TEST_DYN_LINK ; -run core.cpp : : : - common - ; +run config.cpp : : : common ; +run core.cpp : : : common ; +run service.cpp : : : 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 +#include + +#include +#include +#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(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 +#include +#include #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 +#include + +#include +#include +#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); +} + -- cgit v1.2.3