Skip to content

Commit

Permalink
remove naked should_panics (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmwells-amazon authored Oct 5, 2023
1 parent 3131a59 commit 466da4b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
13 changes: 10 additions & 3 deletions cedar-policy-core/src/parser/text_to_cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand All @@ -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]
Expand Down
12 changes: 6 additions & 6 deletions cedar-policy-validator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,6 @@ mod test {
}

#[test]
#[should_panic]
fn cross_fragment_duplicate_type() {
let fragment1: ValidatorSchemaFragment = serde_json::from_value::<SchemaFragment>(json!({
"A": {
Expand All @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion cedar-policy/tests/example_use_cases_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 466da4b

Please sign in to comment.