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/config.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 unittests/config.cpp (limited to 'unittests/config.cpp') 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(); +} + + -- cgit v1.2.3