From a54c7f25a59c45d92d6a870b4e855405b0dd6c44 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Wed, 17 Dec 2025 13:56:51 -0800 Subject: [PATCH] container: root: add getter for `dfi`'s `root` path Adds impl/test for getting absolute path to all `dfi`'s `root` code. --- container/src/root/common/utility.hh | 10 ++++++++++ container/src/root/test/unit/utility.hh | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/container/src/root/common/utility.hh b/container/src/root/common/utility.hh index fc1a220..0b60814 100644 --- a/container/src/root/common/utility.hh +++ b/container/src/root/common/utility.hh @@ -255,6 +255,16 @@ std::string get_env(const std::string& var) return std::string{env}; } +//! \brief Get `dfi`'s root-related code directory +//! \details Operating system path to where all `dfi` root-related code resides +//! \return Operating system absolute path (with trailing slash) +//! \exception type::RuntimeError if unable to get environment +//! \since docker-finance 1.1.0 +std::string get_root_path() +{ + return get_env("DOCKER_FINANCE_CONTAINER_REPO") + "/src/root/"; +} + //! \brief Execute a command in operating system shell //! \param cmd Operating system shell command [args] //! \return Return value of command diff --git a/container/src/root/test/unit/utility.hh b/container/src/root/test/unit/utility.hh index 976989f..5a310b8 100644 --- a/container/src/root/test/unit/utility.hh +++ b/container/src/root/test/unit/utility.hh @@ -327,6 +327,14 @@ TEST_F(CommonFree, get_env) ASSERT_NO_THROW(common::get_env("DOCKER_FINANCE_VERSION")); } +TEST_F(CommonFree, get_root_path) +{ + ASSERT_NO_THROW(common::get_root_path()); + ASSERT_EQ( + common::get_root_path(), + common::get_env("DOCKER_FINANCE_CONTAINER_REPO") + "/src/root/"); +} + TEST_F(CommonFree, exec) { ASSERT_NE(common::exec("should-not-exist"), 0);