|
4 | 4 |
|
5 | 5 | #include "CollectorArgs.h"
|
6 | 6 | #include "CollectorConfig.h"
|
| 7 | +#include "ConfigLoader.h" |
7 | 8 | #include "gmock/gmock.h"
|
8 | 9 | #include "gtest/gtest.h"
|
9 | 10 |
|
@@ -155,4 +156,91 @@ TEST(CollectorConfigTest, TestEnableExternalIpsRuntimeConfig) {
|
155 | 156 | EXPECT_TRUE(config.GetExternalIPsConf().IsEnabled(Direction::BOTH));
|
156 | 157 | }
|
157 | 158 |
|
| 159 | +TEST(CollectorConfigTest, TestIsEnabledIngress) { |
| 160 | + std::string yamlStr = R"( |
| 161 | + networking: |
| 162 | + externalIps: |
| 163 | + enabled: enabled |
| 164 | + direction: ingress |
| 165 | + )"; |
| 166 | + |
| 167 | + YAML::Node yamlNode = YAML::Load(yamlStr); |
| 168 | + CollectorConfig config; |
| 169 | + ASSERT_EQ(ConfigLoader(config).LoadConfiguration(yamlNode), ConfigLoader::SUCCESS) << "Input: " << yamlStr; |
| 170 | + |
| 171 | + auto runtime_config = config.GetRuntimeConfig(); |
| 172 | + |
| 173 | + EXPECT_TRUE(runtime_config.has_value()); |
| 174 | + |
| 175 | + EXPECT_EQ(Direction::INGRESS, config.GetExternalIPsConf().GetDirection()); |
| 176 | + EXPECT_TRUE(config.GetExternalIPsConf().IsEnabled(Direction::INGRESS)); |
| 177 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::EGRESS)); |
| 178 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::BOTH)); |
| 179 | +} |
| 180 | + |
| 181 | +TEST(CollectorConfigTest, TestIsEnabledEgress) { |
| 182 | + std::string yamlStr = R"( |
| 183 | + networking: |
| 184 | + externalIps: |
| 185 | + enabled: enabled |
| 186 | + direction: egress |
| 187 | + )"; |
| 188 | + |
| 189 | + YAML::Node yamlNode = YAML::Load(yamlStr); |
| 190 | + CollectorConfig config; |
| 191 | + ASSERT_EQ(ConfigLoader(config).LoadConfiguration(yamlNode), ConfigLoader::SUCCESS) << "Input: " << yamlStr; |
| 192 | + |
| 193 | + auto runtime_config = config.GetRuntimeConfig(); |
| 194 | + |
| 195 | + EXPECT_TRUE(runtime_config.has_value()); |
| 196 | + |
| 197 | + EXPECT_EQ(Direction::EGRESS, config.GetExternalIPsConf().GetDirection()); |
| 198 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::INGRESS)); |
| 199 | + EXPECT_TRUE(config.GetExternalIPsConf().IsEnabled(Direction::EGRESS)); |
| 200 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::BOTH)); |
| 201 | +} |
| 202 | + |
| 203 | +TEST(CollectorConfigTest, TestIsEnabledBoth) { |
| 204 | + std::string yamlStr = R"( |
| 205 | + networking: |
| 206 | + externalIps: |
| 207 | + enabled: enabled |
| 208 | + direction: both |
| 209 | + )"; |
| 210 | + |
| 211 | + YAML::Node yamlNode = YAML::Load(yamlStr); |
| 212 | + CollectorConfig config; |
| 213 | + ASSERT_EQ(ConfigLoader(config).LoadConfiguration(yamlNode), ConfigLoader::SUCCESS) << "Input: " << yamlStr; |
| 214 | + |
| 215 | + auto runtime_config = config.GetRuntimeConfig(); |
| 216 | + |
| 217 | + EXPECT_TRUE(runtime_config.has_value()); |
| 218 | + |
| 219 | + EXPECT_EQ(Direction::BOTH, config.GetExternalIPsConf().GetDirection()); |
| 220 | + EXPECT_TRUE(config.GetExternalIPsConf().IsEnabled(Direction::INGRESS)); |
| 221 | + EXPECT_TRUE(config.GetExternalIPsConf().IsEnabled(Direction::EGRESS)); |
| 222 | + EXPECT_TRUE(config.GetExternalIPsConf().IsEnabled(Direction::BOTH)); |
| 223 | +} |
| 224 | + |
| 225 | +TEST(CollectorConfigTest, TestIsEnabledNone) { |
| 226 | + std::string yamlStr = R"( |
| 227 | + networking: |
| 228 | + externalIps: |
| 229 | + enabled: disabled |
| 230 | + )"; |
| 231 | + |
| 232 | + YAML::Node yamlNode = YAML::Load(yamlStr); |
| 233 | + CollectorConfig config; |
| 234 | + ASSERT_EQ(ConfigLoader(config).LoadConfiguration(yamlNode), ConfigLoader::SUCCESS) << "Input: " << yamlStr; |
| 235 | + |
| 236 | + auto runtime_config = config.GetRuntimeConfig(); |
| 237 | + |
| 238 | + EXPECT_TRUE(runtime_config.has_value()); |
| 239 | + |
| 240 | + EXPECT_EQ(Direction::NONE, config.GetExternalIPsConf().GetDirection()); |
| 241 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::INGRESS)); |
| 242 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::EGRESS)); |
| 243 | + EXPECT_FALSE(config.GetExternalIPsConf().IsEnabled(Direction::BOTH)); |
| 244 | +} |
| 245 | + |
158 | 246 | } // namespace collector
|
0 commit comments