Skip to content

Commit

Permalink
Add tests;
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed Sep 13, 2019
1 parent 381a05c commit 4784e5c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charmtools/charms.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def validate_deployment(charm, linter):
if field_type is None:
linter.err('deployment.{} is not supported'.format(k))
elif not isinstance(v, field_type):
linter.err('deployment.{} must be {} but got {}'.format(k, field_type, type(v)))
linter.err('deployment.{} must be {} but got {}'.format(k, field_type.__name__, type(v).__name__))


def validate_extra_bindings(charm, linter):
Expand Down
104 changes: 104 additions & 0 deletions tests/test_charm_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from charmtools.charms import validate_actions # noqa
from charmtools.charms import validate_terms # noqa
from charmtools.charms import validate_resources # noqa
from charmtools.charms import validate_deployment # noqa


class TestCharmProof(TestCase):
Expand Down Expand Up @@ -814,6 +815,109 @@ def test_storage_proof_extensions(self):
self.assertEqual(linter.err.call_args_list, [])



class DeploymentValidationTest(TestCase):
def test_deployment(self):
"""Charm has valid deployment."""
linter = Mock()
charm = {
'deployment': {
'type': 'stateful',
'service': 'omit',
'daemonset': True,
'min-version': "1.15",
}
}
validate_deployment(charm, linter)
self.assertFalse(linter.err.called)

def test_deployment_unsupported_field(self):
"""Charm has the invalid deployment field."""
linter = Mock()
charm = {
'deployment': {
'type': 'stateful',
'service': 'omit',
'daemonset': True,
'min-version': "1.15",
'unknow-field': 'xxx',
}
}
validate_deployment(charm, linter)
self.assertEqual(linter.err.call_count, 1)
linter.err.assert_has_calls([
call('deployment.unknow-field is not supported'),
], any_order=True)

def test_deployment_invalid_type(self):
"""Charm has the invalid deployment type."""
linter = Mock()
charm = {
'deployment': {
'type': True,
'service': 'omit',
'daemonset': True,
'min-version': "1.15",
}
}
validate_deployment(charm, linter)
self.assertEqual(linter.err.call_count, 1)
linter.err.assert_has_calls([
call("deployment.type must be str but got bool"),
], any_order=True)

def test_deployment_invalid_service(self):
"""Charm has the invalid deployment service."""
linter = Mock()
charm = {
'deployment': {
'type': 'stateful',
'service': 1,
'daemonset': True,
'min-version': "1.15",
}
}
validate_deployment(charm, linter)
self.assertEqual(linter.err.call_count, 1)
linter.err.assert_has_calls([
call("deployment.service must be str but got int"),
], any_order=True)

def test_deployment_invalid_daemonset(self):
"""Charm has the invalid deployment daemonset."""
linter = Mock()
charm = {
'deployment': {
'type': 'stateful',
'service': 'omit',
'daemonset': 'True',
'min-version': "1.15",
}
}
validate_deployment(charm, linter)
self.assertEqual(linter.err.call_count, 1)
linter.err.assert_has_calls([
call("deployment.daemonset must be bool but got str"),
], any_order=True)

def test_deployment_invalid_min_version(self):
"""Charm has the invalid deployment min-version."""
linter = Mock()
charm = {
'deployment': {
'type': 'stateful',
'service': 'omit',
'daemonset': True,
'min-version': 1.15,
}
}
validate_deployment(charm, linter)
self.assertEqual(linter.err.call_count, 1)
linter.err.assert_has_calls([
call("deployment.min-version must be str but got float"),
], any_order=True)


class ResourcesValidationTest(TestCase):
def test_minimal_resources_config(self):
"""Charm has the minimum allowed resources configuration."""
Expand Down

0 comments on commit 4784e5c

Please sign in to comment.