ai-dev-template / cpp /tests /test_config.cpp
Jordandevlog's picture
Upload cpp/tests/test_config.cpp
c7a3279 verified
Raw
History Blame Contribute Delete
1.09 kB
/**
* @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());
}