def test_return_value_if_cannot_handle(self, can_handle_mock): input = {"Fn::GetAtt": ["id1", "prop1"]} expected = {"Fn::GetAtt": ["id1", "prop1"]} getatt = GetAttAction() can_handle_mock.return_value = False # Simulate failure to handle the input. Result should be same as input self.assertEqual( expected, getatt.resolve_resource_refs(input, self.supported_resource_refs))
def test_must_ignore_missing_properties_with_dot_before(self): input = {"Fn::GetAtt": [".id1", "foo"]} expected = {"Fn::GetAtt": [".id1", "foo"]} getatt = GetAttAction() output = getatt.resolve_resource_id_refs( input, self.supported_resource_id_refs) self.assertEqual(expected, output)
def test_must_resolve_refs_with_many_attributes(self): input = {"Fn::GetAtt": ["id1", "Arn1", "Arn2", "Arn3"]} expected = {"Fn::GetAtt": ["value1", "Arn1", "Arn2", "Arn3"]} getatt = GetAttAction() output = getatt.resolve_resource_id_refs( input, self.supported_resource_id_refs) self.assertEqual(expected, output)
def test_must_resolve_simple_refs(self): input = {"Fn::GetAtt": ["id1.prop1", "Arn"]} expected = {"Fn::GetAtt": ["value1", "Arn"]} getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_return_value_if_cannot_handle(self, can_handle_mock): input = { "Fn::GetAtt": ["id1", "Arn"] } expected = { "Fn::GetAtt": ["id1", "Arn"] } getatt = GetAttAction() can_handle_mock.return_value = False # Simulate failure to handle the input. Result should be same as input self.assertEqual(expected, getatt.resolve_resource_id_refs(input, self.supported_resource_id_refs))
def test_must_ignore_missing_properties_with_dot_before(self): input = { "Fn::GetAtt": [".id1", "foo"] } expected = { "Fn::GetAtt": [".id1", "foo"] } getatt = GetAttAction() output = getatt.resolve_resource_id_refs(input, self.supported_resource_id_refs) self.assertEqual(expected, output)
def test_must_ignore_refs_without_attributes_in_concatenated_form(self): input = { # No actual attributes. with just only one entry in array, the value never gets resolved "Fn::GetAtt": ["id1.prop1"] } expected = {"Fn::GetAtt": ["id1.prop1"]} getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_ignore_refs_without_attributes(self): input = { # No actual attributes. But since we have two entries in the array, we try to resolve them "Fn::GetAtt": ["id1", "prop1"] } expected = {"Fn::GetAtt": ["value1"]} getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_resolve_with_splitted_resource_refs(self): input = { # Reference to resource `id1.prop1` is split into different elements "Fn::GetAtt": ["id1", "prop1", "Arn1", "Arn2", "Arn3"] } expected = {"Fn::GetAtt": ["value1", "Arn1", "Arn2", "Arn3"]} getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_ignore_invalid_value_array(self): input = { # No actual attributes "Fn::GetAtt": ["id1"] } expected = {"Fn::GetAtt": ["id1"]} getatt = GetAttAction() output = getatt.resolve_resource_id_refs( input, self.supported_resource_id_refs) self.assertEqual(expected, output)
def test_must_resolve_refs_with_many_attributes(self): input = { "Fn::GetAtt": ["id1", "Arn1", "Arn2", "Arn3"] } expected = { "Fn::GetAtt": ["value1", "Arn1", "Arn2", "Arn3"] } getatt = GetAttAction() output = getatt.resolve_resource_id_refs(input, self.supported_resource_id_refs) self.assertEqual(expected, output)
def test_must_resolve_simple_refs(self): input = { "Fn::GetAtt": ["id1.prop1", "Arn"] } expected = { "Fn::GetAtt": ["value1", "Arn"] } getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_ignore_invalid_value_array(self): input = { # No actual attributes "Fn::GetAtt": ["id1"] } expected = { "Fn::GetAtt": ["id1"] } getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEquals(expected, output)
def test_must_ignore_invalid_value_type(self): input = { # No actual attributes "Fn::GetAtt": {"a": "b"} } expected = { "Fn::GetAtt": {"a": "b"} } getatt = GetAttAction() output = getatt.resolve_resource_id_refs(input, self.supported_resource_id_refs) self.assertEqual(expected, output)
def test_must_ignore_refs_without_attributes_in_concatenated_form(self): input = { # No actual attributes. with just only one entry in array, the value never gets resolved "Fn::GetAtt": ["id1.prop1"] } expected = { "Fn::GetAtt": ["id1.prop1"] } getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_ignore_refs_without_attributes(self): input = { # No actual attributes. But since we have two entries in the array, we try to resolve them "Fn::GetAtt": ["id1", "prop1"] } expected = { "Fn::GetAtt": ["value1"] } getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_resolve_with_splitted_resource_refs(self): input = { # Reference to resource `id1.prop1` is split into different elements "Fn::GetAtt": ["id1", "prop1", "Arn1", "Arn2", "Arn3"] } expected = { "Fn::GetAtt": ["value1", "Arn1", "Arn2", "Arn3"] } getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEqual(expected, output)
def test_must_ignore_invalid_value_type(self): input = { # No actual attributes "Fn::GetAtt": { "a": "b" } } expected = {"Fn::GetAtt": {"a": "b"}} getatt = GetAttAction() output = getatt.resolve_resource_refs(input, self.supported_resource_refs) self.assertEquals(expected, output)
def test_must_do_nothing(self): # Parameter references are not resolved by GetAtt input = "foo" expected = "foo" supported_resource_refs = Mock() self.assertEqual( expected, GetAttAction().resolve_parameter_refs(input, supported_resource_refs)) supported_resource_refs.assert_not_called()