/** * @file test_config.cpp * @brief Tests for configuration loading. */ #include #include "core/config.hpp" #include using namespace app::core; class ConfigTest : public ::testing::Test { protected: void TearDown() override { // Clean up environment unsetenv("APP_NAME"); unsetenv("PORT"); unsetenv("DEBUG"); } }; TEST_F(ConfigTest, DefaultValues) { auto result = Config::from_env(); ASSERT_TRUE(result.has_value()); EXPECT_EQ(result->app_name, "MyApp"); EXPECT_EQ(result->port, 8080); EXPECT_FALSE(result->debug); } TEST_F(ConfigTest, FromEnvironment) { setenv("APP_NAME", "TestApp", 1); setenv("PORT", "3000", 1); setenv("DEBUG", "true", 1); auto result = Config::from_env(); ASSERT_TRUE(result.has_value()); EXPECT_EQ(result->app_name, "TestApp"); EXPECT_EQ(result->port, 3000); EXPECT_TRUE(result->debug); } TEST_F(ConfigTest, InvalidPort) { setenv("PORT", "not_a_number", 1); auto result = Config::from_env(); EXPECT_FALSE(result.has_value()); }