Skip to content

Commit

Permalink
fix: additional tests and bug fixes (#104)
Browse files Browse the repository at this point in the history
* additional test and bug fixes

* fix some minor whitespace

---------

Co-authored-by: Hogan Bobertz <bobertzh@amazon.com>
  • Loading branch information
HBobertz and Hogan Bobertz committed Apr 20, 2023
1 parent 70f01a4 commit 1913673
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
.vscode/
.vscode/
node_modules/
2 changes: 1 addition & 1 deletion src/parser/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
75 changes: 75 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand Down

0 comments on commit 1913673

Please sign in to comment.