Skip to content

Commit eb17212

Browse files
Pierre-Luc GagnéCopilot
andcommitted
refactor: remove dotenv-cpp dependency from integration tests
Replace dotenv::getenv() calls with a local getenv_or() lambda wrapping std::getenv(), using the same key/fallback pattern. This removes the laserpants/dotenv-cpp FetchContent fetch, the dotenv link target, and the <dotenv.h> include entirely. The integration test already receives all connection parameters via process environment variables set by CMake set_tests_properties(), so no .env file loading was actually needed at runtime. Also remove dotenv-cpp from README.md dependencies list. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 35624f3 commit eb17212

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ Automatically fetched via CMake FetchContent:
215215

216216
- [Boost.PFR](https://github.com/boostorg/pfr) — compile-time struct reflection (header-only)
217217
- [boost.ut](https://github.com/boost-ext/ut) v2.1.0 — unit testing (test builds only)
218-
- [dotenv-cpp](https://github.com/laserpants/dotenv-cpp)`.env` file loading (integration tests only)
219218

220219
System dependencies:
221220

tests/integration/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ if(NOT TARGET Boost::ut)
1414
FetchContent_MakeAvailable(boost_ut)
1515
endif()
1616

17-
# dotenv-cpp (header-only, for .env file loading in integration tests)
18-
if(NOT TARGET dotenv)
19-
include(FetchContent)
20-
set(BUILD_DOCS OFF CACHE BOOL "Disable dependency docs generation" FORCE)
21-
FetchContent_Declare(
22-
laserpants_dotenv
23-
GIT_REPOSITORY https://github.com/laserpants/dotenv-cpp.git
24-
GIT_TAG master
25-
GIT_SHALLOW TRUE
26-
)
27-
FetchContent_MakeAvailable(laserpants_dotenv)
28-
endif()
29-
3017
find_package(PkgConfig REQUIRED)
3118

3219
# Add integration test cmake modules path
@@ -45,7 +32,6 @@ target_link_libraries(tests_integration_ds_mysql
4532
PRIVATE
4633
ds_mysql
4734
Boost::ut
48-
dotenv
4935
)
5036

5137
# Link with MySQL client library

tests/integration/mysql/test_query_builder.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#include <dotenv.h>
2-
31
#include <boost/ut.hpp>
42
#include <chrono>
3+
#include <cstdlib>
54
#include <optional>
65
#include <string>
76
#include <vector>
@@ -43,18 +42,23 @@ struct trade {
4342
};
4443

4544
[[nodiscard]] std::optional<mysql_config> mysql_config_from_env() {
46-
const std::string host = dotenv::getenv("DS_MYSQL_TEST_HOST", "");
47-
const std::string database = dotenv::getenv("DS_MYSQL_TEST_DATABASE", "ds_mysql_test");
48-
const std::string user = dotenv::getenv("DS_MYSQL_TEST_USER", "");
49-
const std::string password = dotenv::getenv("DS_MYSQL_TEST_PASSWORD", "");
45+
auto getenv_or = [](char const* key, char const* fallback = "") -> std::string {
46+
char const* v = std::getenv(key);
47+
return v ? v : fallback;
48+
};
49+
50+
const std::string host = getenv_or("DS_MYSQL_TEST_HOST");
51+
const std::string database = getenv_or("DS_MYSQL_TEST_DATABASE", "ds_mysql_test");
52+
const std::string user = getenv_or("DS_MYSQL_TEST_USER");
53+
const std::string password = getenv_or("DS_MYSQL_TEST_PASSWORD");
5054

5155
if (host.empty() || user.empty() || password.empty()) {
5256
return std::nullopt;
5357
}
5458

55-
const std::string port_env =
56-
dotenv::getenv("DS_MYSQL_TEST_PORT", std::to_string(default_mysql_port.to_unsigned_int()));
57-
const auto parsed_port = static_cast<unsigned int>(std::stoul(port_env));
59+
const std::string port_str =
60+
getenv_or("DS_MYSQL_TEST_PORT", std::to_string(default_mysql_port.to_unsigned_int()).c_str());
61+
const auto parsed_port = static_cast<unsigned int>(std::stoul(port_str));
5862

5963
return mysql_config{
6064
host_name{host},

0 commit comments

Comments
 (0)