diff --git a/.gitignore b/.gitignore index 32e5e394..ac2b3e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk -.vscode/ \ No newline at end of file +.vscode/ +node_modules/ \ No newline at end of file diff --git a/src/parser/resource.rs b/src/parser/resource.rs index 72d7c978..54ed8186 100644 --- a/src/parser/resource.rs +++ b/src/parser/resource.rs @@ -91,7 +91,7 @@ pub fn build_resources( } let deletion_policy = resource_object - .get("UpdatePolicy") + .get("DeletionPolicy") .and_then(|x| x.as_str()) .map(|x| x.to_string()); diff --git a/tests/tests.rs b/tests/tests.rs index 4da39b40..d2a03775 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -83,6 +83,81 @@ fn test_basic_parse_tree_with_condition() { assert_resource_equal(a, resource); } +#[test] +fn test_basic_parse_tree_with_metadata() { + let a: Value = serde_json::json!({ + "LogicalResource": { + "Type": "AWS::IAM::Role", + "Metadata": { + "myArbitrary": "objectData" + }, + "Properties": { + "RoleName": "bob", + "AssumeTime": 20, + "Bool": true, + "NotExistent": {"Ref": "AWS::NoValue"}, + "Array": ["hi", "there"] + } + } + }); + + let resource = ResourceParseTree { + name: "LogicalResource".into(), + condition: Option::None, + metadata: Option::Some(ResourceValue::Object(map! { + "myArbitrary" => ResourceValue::String("objectData".into()) + })), + update_policy: Option::None, + deletion_policy: Option::None, + dependencies: vec![], + resource_type: "AWS::IAM::Role".into(), + properties: map! { + "RoleName" => ResourceValue::String("bob".into()), + "AssumeTime" => ResourceValue::Number(20), + "Bool" => ResourceValue::Bool(true), + "NotExistent" => ResourceValue::Null, + "Array" => ResourceValue::Array(vec![ResourceValue::String("hi".into()), ResourceValue::String("there".into())]) + }, + }; + assert_resource_equal(a, resource); +} + +#[test] +fn test_parse_tree_basics_with_deletion_policy() { + let a: Value = serde_json::json!({ + "LogicalResource": { + "Type": "AWS::IAM::Role", + "DeletionPolicy": "Retain", + "Properties": { + "RoleName": "bob", + "AssumeTime": 20, + "Bool": true, + "NotExistent": {"Ref": "AWS::NoValue"}, + "Array": ["hi", "there"] + } + } + }); + + let resource: ResourceParseTree = ResourceParseTree { + name: "LogicalResource".into(), + condition: Option::None, + metadata: Option::None, + update_policy: Option::None, + deletion_policy: Option::Some("Retain".into()), + dependencies: vec![], + resource_type: "AWS::IAM::Role".into(), + properties: map! { + "RoleName" => ResourceValue::String("bob".into()), + "AssumeTime" => ResourceValue::Number(20), + "Bool" => ResourceValue::Bool(true), + "NotExistent" => ResourceValue::Null, + "Array" => ResourceValue::Array(vec![ResourceValue::String("hi".into()), ResourceValue::String("there".into())]) + }, + }; + + assert_resource_equal(a, resource); +} + #[test] fn test_parse_tree_sub_str() { let a = serde_json::json!({