def test_resources_invalid_values(self): """Charm has resources with invalid values.""" linter = Mock() charm = {"resources": {"buzz": {"type": "snap"}}} validate_resources(charm, linter) self.assertEqual(linter.err.call_count, 1) linter.err.assert_has_calls([call('resources.buzz.type: "snap" is not one of file')], any_order=True)
def test_resources_without_defs(self): """Charm has resources key but no definitions.""" linter = Mock() charm = {"resources": {}} validate_resources(charm, linter) self.assertEqual(linter.err.call_count, 1) linter.err.assert_has_calls([call("resources: must be a dictionary of resource definitions")], any_order=True)
def test_resources_unknown_keys(self): """Charm has resources with illegal keys.""" linter = Mock() charm = {"resources": {"vm": {"type": "file", "unknown": "invalid key"}}} validate_resources(charm, linter) self.assertEqual(linter.err.call_count, 1) linter.err.assert_has_calls( [call("resources.vm: Unrecognized keys in mapping: " "\"{'unknown': 'invalid key'}\"")], any_order=True )
def test_resources_without_defs(self): """Charm has resources key but no definitions.""" linter = Mock() charm = {'resources': {}} validate_resources(charm, linter) self.assertEqual(linter.err.call_count, 1) linter.err.assert_has_calls([ call('resources: must be a dictionary of resource definitions'), ], any_order=True)
def test_minimal_resources_config(self): """Charm has the minimum allowed resources configuration.""" linter = Mock() charm = { 'resources': { 'test': { 'type': 'file', 'filename': 'file.tgz', } } } validate_resources(charm, linter) self.assertFalse(linter.err.called)
def test_resources_invalid_values(self): """Charm has resources with invalid values.""" linter = Mock() charm = { 'resources': { 'buzz': { 'type': 'snap', }, } } validate_resources(charm, linter) self.assertEqual(linter.err.call_count, 1) linter.err.assert_has_calls([ call('resources.buzz.type: "snap" is not one of file, oci-image'), ], any_order=True)
def test_resources_unknown_keys(self): """Charm has resources with illegal keys.""" linter = Mock() charm = { 'resources': { 'vm': { 'type': 'file', 'unknown': 'invalid key', }, } } validate_resources(charm, linter) self.assertEqual(linter.err.call_count, 1) linter.err.assert_has_calls([ call('resources.vm: Unrecognized keys in mapping: ' '"{\'unknown\': \'invalid key\'}"'), ], any_order=True)
def test_resources_proof_extensions(self): """Charm has resources with proof extensions.""" linter = Mock() charm = { 'resources': { 'vm': { 'type': 'file', 'unknown': 'invalid key', }, } } extensions = [ { 'name': 'unknown', 'type': 'String', } ] validate_resources(charm, linter, extensions) self.assertEqual(linter.err.call_args_list, [])
def test_minimal_resources_config(self): """Charm has the minimum allowed resources configuration.""" linter = Mock() charm = {"resources": {"test": {"type": "file", "filename": "file.tgz"}}} validate_resources(charm, linter) self.assertFalse(linter.err.called)