(t *testing.T)
| 1412 | } |
| 1413 | |
| 1414 | func TestResidualAstComplex(t *testing.T) { |
| 1415 | env := testEnv(t, |
| 1416 | Variable("resource.name", StringType), |
| 1417 | Variable("request.time", TimestampType), |
| 1418 | Variable("request.auth.claims", MapType(StringType, StringType)), |
| 1419 | ) |
| 1420 | unkVars, _ := PartialVars( |
| 1421 | map[string]any{ |
| 1422 | "resource.name": "bucket/my-bucket/objects/private", |
| 1423 | "request.auth.claims": map[string]string{ |
| 1424 | "email_verified": "true", |
| 1425 | }, |
| 1426 | }, |
| 1427 | AttributePattern("request.auth.claims").QualString("email"), |
| 1428 | ) |
| 1429 | ast, iss := env.Compile( |
| 1430 | `resource.name.startsWith("bucket/my-bucket") && |
| 1431 | bool(request.auth.claims.email_verified) == true && |
| 1432 | request.auth.claims.email == "wiley@acme.co"`) |
| 1433 | if iss.Err() != nil { |
| 1434 | t.Fatalf("env.Compile() failed: %v", iss.Err()) |
| 1435 | } |
| 1436 | prg, err := env.Program(ast, |
| 1437 | EvalOptions(OptTrackState, OptPartialEval), |
| 1438 | ) |
| 1439 | if err != nil { |
| 1440 | t.Fatalf("env.Program() failed: %v", err) |
| 1441 | } |
| 1442 | out, det, err := prg.Eval(unkVars) |
| 1443 | if !types.IsUnknown(out) { |
| 1444 | t.Fatalf("got %v, expected unknown", out) |
| 1445 | } |
| 1446 | if err != nil { |
| 1447 | t.Fatal(err) |
| 1448 | } |
| 1449 | residual, err := env.ResidualAst(ast, det) |
| 1450 | if err != nil { |
| 1451 | t.Fatal(err) |
| 1452 | } |
| 1453 | expr, err := AstToString(residual) |
| 1454 | if err != nil { |
| 1455 | t.Fatal(err) |
| 1456 | } |
| 1457 | if expr != `request.auth.claims.email == "wiley@acme.co"` { |
| 1458 | t.Errorf("got expr: %s, wanted request.auth.claims.email == \"wiley@acme.co\"", expr) |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | func TestResidualAstMacros(t *testing.T) { |
| 1463 | tests := []struct { |
nothing calls this directly
no test coverage detected