|
3 | 3 | #include "google/api/expr/v1alpha1/syntax.pb.h" |
4 | 4 | #include "gmock/gmock.h" |
5 | 5 | #include "gtest/gtest.h" |
| 6 | +#include "absl/status/status.h" |
6 | 7 | #include "absl/status/statusor.h" |
7 | 8 | #include "eval/eval/ident_step.h" |
8 | 9 | #include "eval/public/cel_attribute.h" |
@@ -32,7 +33,6 @@ absl::StatusOr<CelValue> RunExpression(const CelValue target, |
32 | 33 | absl::string_view unknown_path, |
33 | 34 | bool enable_unknowns) { |
34 | 35 | ExecutionPath path; |
35 | | - |
36 | 36 | Expr dummy_expr; |
37 | 37 |
|
38 | 38 | auto select = dummy_expr.mutable_select_expr(); |
@@ -179,6 +179,43 @@ TEST_P(SelectStepTest, MapPresenseIsTrueTest) { |
179 | 179 | EXPECT_EQ(result.BoolOrDie(), true); |
180 | 180 | } |
181 | 181 |
|
| 182 | +TEST(SelectStepTest, MapPresenseIsErrorTest) { |
| 183 | + TestMessage message; |
| 184 | + google::protobuf::Arena arena; |
| 185 | + |
| 186 | + Expr select_expr; |
| 187 | + auto select = select_expr.mutable_select_expr(); |
| 188 | + select->set_field("1"); |
| 189 | + select->set_test_only(true); |
| 190 | + Expr* expr1 = select->mutable_operand(); |
| 191 | + auto select_map = expr1->mutable_select_expr(); |
| 192 | + select_map->set_field("int32_int32_map"); |
| 193 | + Expr* expr0 = select_map->mutable_operand(); |
| 194 | + auto ident = expr0->mutable_ident_expr(); |
| 195 | + ident->set_name("target"); |
| 196 | + |
| 197 | + auto step0_status = CreateIdentStep(ident, expr0->id()); |
| 198 | + auto step1_status = CreateSelectStep(select_map, expr1->id(), ""); |
| 199 | + auto step2_status = CreateSelectStep(select, select_expr.id(), ""); |
| 200 | + ASSERT_OK(step0_status); |
| 201 | + ASSERT_OK(step1_status); |
| 202 | + ASSERT_OK(step2_status); |
| 203 | + |
| 204 | + ExecutionPath path; |
| 205 | + path.push_back(std::move(step0_status.value())); |
| 206 | + path.push_back(std::move(step1_status.value())); |
| 207 | + path.push_back(std::move(step2_status.value())); |
| 208 | + CelExpressionFlatImpl cel_expr(&select_expr, std::move(path), 0, {}, false); |
| 209 | + Activation activation; |
| 210 | + activation.InsertValue("target", |
| 211 | + CelProtoWrapper::CreateMessage(&message, &arena)); |
| 212 | + auto status = cel_expr.Evaluate(activation, &arena); |
| 213 | + CelValue result = status.value(); |
| 214 | + |
| 215 | + EXPECT_TRUE(result.IsError()); |
| 216 | + EXPECT_EQ(result.ErrorOrDie()->code(), absl::StatusCode::kInvalidArgument); |
| 217 | +} |
| 218 | + |
182 | 219 | TEST(SelectStepTest, MapPresenseIsTrueWithUnknownTest) { |
183 | 220 | UnknownSet unknown_set; |
184 | 221 | std::string key1 = "key1"; |
|
0 commit comments