File size: 1,093 Bytes
c7a3279 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /**
* @file test_config.cpp
* @brief Tests for configuration loading.
*/
#include <gtest/gtest.h>
#include "core/config.hpp"
#include <cstdlib>
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());
}
|