From 466da4bc3163a72373997a91f62f7c77153f2792 Mon Sep 17 00:00:00 2001 From: Andrew Wells <130512013+andrewmwells-amazon@users.noreply.github.com> Date: Thu, 5 Oct 2023 08:15:32 -0700 Subject: [PATCH] remove naked should_panics (#338) --- .../integration_tests/example_use_cases_doc.rs | 4 +++- cedar-policy-core/src/parser/text_to_cst.rs | 13 ++++++++++--- cedar-policy-validator/src/schema.rs | 12 ++++++------ cedar-policy/tests/example_use_cases_doc.rs | 4 +++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cedar-policy-cli/tests/integration_tests/example_use_cases_doc.rs b/cedar-policy-cli/tests/integration_tests/example_use_cases_doc.rs index 074e2141b..b468d54c0 100644 --- a/cedar-policy-cli/tests/integration_tests/example_use_cases_doc.rs +++ b/cedar-policy-cli/tests/integration_tests/example_use_cases_doc.rs @@ -68,7 +68,9 @@ fn scenario_4a() { // note: 4b currently omitted because it requires date/timestamp functionality /// currently failing, as the validator does not support action attributes -#[should_panic] +#[should_panic( + expected = "error occurred while evaluating policy `policy0`: `Action::\\\"view\\\"` does not have the attribute: readOnly" +)] #[test] fn scenario_4c() { perform_integration_test_from_json(folder().join("4c.json")); diff --git a/cedar-policy-core/src/parser/text_to_cst.rs b/cedar-policy-core/src/parser/text_to_cst.rs index c888eb94a..0050f7d7e 100644 --- a/cedar-policy-core/src/parser/text_to_cst.rs +++ b/cedar-policy-core/src/parser/text_to_cst.rs @@ -335,8 +335,7 @@ mod tests { assert!(policy.is_ok()); } - #[test] - #[should_panic] // we no longer support structs + #[test] // we no longer support named structs fn member7() { let policy = parse_policy( r#" @@ -346,7 +345,15 @@ mod tests { }; "#, ); - assert!(policy.is_ok()); + let errs = match policy.err() { + Some(pes) => pes, + _ => panic!("Expected parsing policy to error"), + }; + assert!(errs.len() == 2); + assert!(format!("{:?}", errs[0]) + .contains("ToCST(ToCSTError { err: UnrecognizedToken { token: (98, \"{\", 99)")); + assert!(format!("{:?}", errs[1]) + .contains("ToCST(ToCSTError { err: UnrecognizedToken { token: (141, \"}\", 142)")); } #[test] diff --git a/cedar-policy-validator/src/schema.rs b/cedar-policy-validator/src/schema.rs index fe390ceb8..15a6a702e 100644 --- a/cedar-policy-validator/src/schema.rs +++ b/cedar-policy-validator/src/schema.rs @@ -2617,7 +2617,6 @@ mod test { } #[test] - #[should_panic] fn cross_fragment_duplicate_type() { let fragment1: ValidatorSchemaFragment = serde_json::from_value::(json!({ "A": { @@ -2643,12 +2642,13 @@ mod test { .unwrap() .try_into() .unwrap(); - let schema = ValidatorSchema::from_schema_fragments([fragment1, fragment2]).unwrap(); - assert_eq!( - schema.entity_types.iter().next().unwrap().1.attributes, - Attributes::with_required_attributes([("a".into(), Type::primitive_long())]) - ); + let schema = ValidatorSchema::from_schema_fragments([fragment1, fragment2]); + + match schema { + Err(SchemaError::DuplicateCommonType(s)) if s.contains("A::MyLong") => (), + _ => panic!("should have errored because schema fragments have duplicate types"), + }; } #[test] diff --git a/cedar-policy/tests/example_use_cases_doc.rs b/cedar-policy/tests/example_use_cases_doc.rs index fa909d8e3..3484e3847 100644 --- a/cedar-policy/tests/example_use_cases_doc.rs +++ b/cedar-policy/tests/example_use_cases_doc.rs @@ -68,7 +68,9 @@ fn scenario_4a() { // note: 4b currently omitted because it requires date/timestamp functionality /// currently failing, as the validator does not support action attributes -#[should_panic] +#[should_panic( + expected = "error occurred while evaluating policy `policy0`: entity does not exist: Action::\\\"view\\\"" +)] #[test] fn scenario_4c() { perform_integration_test_from_json(folder().join("4c.json"));