|
14 | 14 | #include "test/mocks/matcher/mocks.h"
|
15 | 15 | #include "test/mocks/server/factory_context.h"
|
16 | 16 | #include "test/test_common/registry.h"
|
| 17 | +#include "test/test_common/test_runtime.h" |
17 | 18 | #include "test/test_common/utility.h"
|
18 | 19 |
|
19 | 20 | #include "gtest/gtest.h"
|
@@ -133,6 +134,213 @@ TEST_F(MatcherTest, TestPrefixMatcher) {
|
133 | 134 | EXPECT_THAT(result, HasResult(IsStringAction("expected!")));
|
134 | 135 | }
|
135 | 136 |
|
| 137 | +TEST_F(MatcherTest, TestPrefixMatcherWithRetryInnerMissPerformsOuterOnNoMatch) { |
| 138 | + const std::string yaml = R"EOF( |
| 139 | +on_no_match: |
| 140 | + action: |
| 141 | + name: test_action |
| 142 | + typed_config: |
| 143 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 144 | + value: expected! |
| 145 | +matcher_tree: |
| 146 | + input: |
| 147 | + name: outer_input |
| 148 | + typed_config: |
| 149 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 150 | + prefix_match_map: |
| 151 | + map: |
| 152 | + "": |
| 153 | + matcher: |
| 154 | + matcher_list: |
| 155 | + matchers: |
| 156 | + - predicate: |
| 157 | + single_predicate: |
| 158 | + input: |
| 159 | + name: inner_input |
| 160 | + typed_config: |
| 161 | + "@type": type.googleapis.com/google.protobuf.BoolValue |
| 162 | + value_match: |
| 163 | + exact: foo |
| 164 | + on_match: |
| 165 | + action: |
| 166 | + name: test_action |
| 167 | + typed_config: |
| 168 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 169 | + value: unexpected |
| 170 | + val: |
| 171 | + matcher: |
| 172 | + matcher_list: |
| 173 | + matchers: |
| 174 | + - predicate: |
| 175 | + single_predicate: |
| 176 | + input: |
| 177 | + name: inner_input |
| 178 | + typed_config: |
| 179 | + "@type": type.googleapis.com/google.protobuf.BoolValue |
| 180 | + value_match: |
| 181 | + exact: foo |
| 182 | + on_match: |
| 183 | + action: |
| 184 | + name: test_action |
| 185 | + typed_config: |
| 186 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 187 | + value: unexpected |
| 188 | + )EOF"; |
| 189 | + |
| 190 | + envoy::config::common::matcher::v3::Matcher matcher; |
| 191 | + MessageUtil::loadFromYaml(yaml, matcher, ProtobufMessage::getStrictValidationVisitor()); |
| 192 | + |
| 193 | + TestUtility::validate(matcher); |
| 194 | + |
| 195 | + auto outer_factory = TestDataInputStringFactory("value"); |
| 196 | + auto inner_factory = TestDataInputBoolFactory("bar"); |
| 197 | + |
| 198 | + EXPECT_CALL(validation_visitor_, |
| 199 | + performDataInputValidation(_, "type.googleapis.com/google.protobuf.StringValue")); |
| 200 | + EXPECT_CALL(validation_visitor_, |
| 201 | + performDataInputValidation(_, "type.googleapis.com/google.protobuf.BoolValue")) |
| 202 | + .Times(2); |
| 203 | + auto match_tree = factory_.create(matcher); |
| 204 | + |
| 205 | + const auto result = match_tree()->match(TestData()); |
| 206 | + EXPECT_THAT(result, HasStringAction("expected!")); |
| 207 | +} |
| 208 | + |
| 209 | +TEST_F(MatcherTest, TestPrefixMatcherWithRetryInnerMissRetriesShorterPrefix) { |
| 210 | + const std::string yaml = R"EOF( |
| 211 | +matcher_tree: |
| 212 | + input: |
| 213 | + name: outer_input |
| 214 | + typed_config: |
| 215 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 216 | + prefix_match_map: |
| 217 | + map: |
| 218 | + val: |
| 219 | + matcher: |
| 220 | + matcher_list: |
| 221 | + matchers: |
| 222 | + - predicate: |
| 223 | + single_predicate: |
| 224 | + input: |
| 225 | + name: inner_input |
| 226 | + typed_config: |
| 227 | + "@type": type.googleapis.com/google.protobuf.BoolValue |
| 228 | + value_match: |
| 229 | + exact: bar |
| 230 | + on_match: |
| 231 | + action: |
| 232 | + name: test_action |
| 233 | + typed_config: |
| 234 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 235 | + value: expected! |
| 236 | + valu: |
| 237 | + matcher: |
| 238 | + matcher_list: |
| 239 | + matchers: |
| 240 | + - predicate: |
| 241 | + single_predicate: |
| 242 | + input: |
| 243 | + name: inner_input |
| 244 | + typed_config: |
| 245 | + "@type": type.googleapis.com/google.protobuf.BoolValue |
| 246 | + value_match: |
| 247 | + exact: foo |
| 248 | + on_match: |
| 249 | + action: |
| 250 | + name: test_action |
| 251 | + typed_config: |
| 252 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 253 | + value: not expected |
| 254 | + )EOF"; |
| 255 | + |
| 256 | + envoy::config::common::matcher::v3::Matcher matcher; |
| 257 | + MessageUtil::loadFromYaml(yaml, matcher, ProtobufMessage::getStrictValidationVisitor()); |
| 258 | + |
| 259 | + TestUtility::validate(matcher); |
| 260 | + |
| 261 | + auto outer_factory = TestDataInputStringFactory("value"); |
| 262 | + auto inner_factory = TestDataInputBoolFactory("bar"); |
| 263 | + |
| 264 | + EXPECT_CALL(validation_visitor_, |
| 265 | + performDataInputValidation(_, "type.googleapis.com/google.protobuf.StringValue")); |
| 266 | + EXPECT_CALL(validation_visitor_, |
| 267 | + performDataInputValidation(_, "type.googleapis.com/google.protobuf.BoolValue")) |
| 268 | + .Times(2); |
| 269 | + auto match_tree = factory_.create(matcher); |
| 270 | + |
| 271 | + const auto result = match_tree()->match(TestData()); |
| 272 | + EXPECT_THAT(result, HasStringAction("expected!")); |
| 273 | +} |
| 274 | + |
| 275 | +TEST_F(MatcherTest, TestPrefixMatcherWithoutRetryInnerMissDoesNotRetryShorterPrefix) { |
| 276 | + TestScopedRuntime scoped_runtime; |
| 277 | + scoped_runtime.mergeValues( |
| 278 | + {{"envoy.reloadable_features.prefix_map_matcher_resume_after_subtree_miss", "false"}}); |
| 279 | + const std::string yaml = R"EOF( |
| 280 | +matcher_tree: |
| 281 | + input: |
| 282 | + name: outer_input |
| 283 | + typed_config: |
| 284 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 285 | + prefix_match_map: |
| 286 | + map: |
| 287 | + val: |
| 288 | + matcher: |
| 289 | + matcher_list: |
| 290 | + matchers: |
| 291 | + - predicate: |
| 292 | + single_predicate: |
| 293 | + input: |
| 294 | + name: inner_input |
| 295 | + typed_config: |
| 296 | + "@type": type.googleapis.com/google.protobuf.BoolValue |
| 297 | + value_match: |
| 298 | + exact: bar |
| 299 | + on_match: |
| 300 | + action: |
| 301 | + name: test_action |
| 302 | + typed_config: |
| 303 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 304 | + value: expected! |
| 305 | + valu: |
| 306 | + matcher: |
| 307 | + matcher_list: |
| 308 | + matchers: |
| 309 | + - predicate: |
| 310 | + single_predicate: |
| 311 | + input: |
| 312 | + name: inner_input |
| 313 | + typed_config: |
| 314 | + "@type": type.googleapis.com/google.protobuf.BoolValue |
| 315 | + value_match: |
| 316 | + exact: foo |
| 317 | + on_match: |
| 318 | + action: |
| 319 | + name: test_action |
| 320 | + typed_config: |
| 321 | + "@type": type.googleapis.com/google.protobuf.StringValue |
| 322 | + value: not expected |
| 323 | + )EOF"; |
| 324 | + |
| 325 | + envoy::config::common::matcher::v3::Matcher matcher; |
| 326 | + MessageUtil::loadFromYaml(yaml, matcher, ProtobufMessage::getStrictValidationVisitor()); |
| 327 | + |
| 328 | + TestUtility::validate(matcher); |
| 329 | + |
| 330 | + auto outer_factory = TestDataInputStringFactory("value"); |
| 331 | + auto inner_factory = TestDataInputBoolFactory("bar"); |
| 332 | + |
| 333 | + EXPECT_CALL(validation_visitor_, |
| 334 | + performDataInputValidation(_, "type.googleapis.com/google.protobuf.StringValue")); |
| 335 | + EXPECT_CALL(validation_visitor_, |
| 336 | + performDataInputValidation(_, "type.googleapis.com/google.protobuf.BoolValue")) |
| 337 | + .Times(2); |
| 338 | + auto match_tree = factory_.create(matcher); |
| 339 | + |
| 340 | + const auto result = match_tree()->match(TestData()); |
| 341 | + EXPECT_THAT(result, HasNoMatch()); |
| 342 | +} |
| 343 | + |
136 | 344 | TEST_F(MatcherTest, TestInvalidFloatPrefixMapMatcher) {
|
137 | 345 | const std::string yaml = R"EOF(
|
138 | 346 | matcher_tree:
|
|
0 commit comments