diff --git a/tests/units/nulecule/test_lib.py b/tests/units/nulecule/test_lib.py index 742738d8..d9e56dac 100644 --- a/tests/units/nulecule/test_lib.py +++ b/tests/units/nulecule/test_lib.py @@ -3,6 +3,7 @@ from atomicapp.nulecule.lib import NuleculeBase from atomicapp.nulecule.exceptions import NuleculeException +from atomicapp.nulecule.config import Config class TestNuleculeBaseGetProvider(unittest.TestCase): @@ -16,7 +17,7 @@ def test_get_provider_success(self): provider_key = u'openshift' # method `get_provider` will read from this config, we give it here # since we have neither provided it before nor it is auto-generated - nb.config = {u'general': {u'provider': provider_key}} + nb.config = Config(answers={u'general': {u'provider': provider_key}}) return_provider = mock.Mock() # mocking return value of method plugin.getProvider,because it returns @@ -35,6 +36,6 @@ def test_get_provider_failure(self): nb = NuleculeBase(params = [], basepath = '', namespace = '') # purposefully give the wrong provider key provider_key = u'mesos' - nb.config = {u'general': {u'provider': provider_key}} + nb.config = Config(answers={u'general': {u'provider': provider_key}}) with self.assertRaises(NuleculeException): nb.get_provider() diff --git a/tests/units/nulecule/test_nulecule.py b/tests/units/nulecule/test_nulecule.py index 1bb60179..6392949d 100644 --- a/tests/units/nulecule/test_nulecule.py +++ b/tests/units/nulecule/test_nulecule.py @@ -4,6 +4,7 @@ import os from atomicapp.nulecule.base import Nulecule from atomicapp.nulecule.exceptions import NuleculeException +from atomicapp.nulecule.config import Config class TestNuleculeRun(unittest.TestCase): @@ -15,8 +16,9 @@ def test_run(self): dryrun = False mock_component_1 = mock.Mock() mock_component_2 = mock.Mock() + config = Config(answers={}) - n = Nulecule('some-id', '0.0.2', [{}], 'some/path', {}) + n = Nulecule('some-id', '0.0.2', [{}], 'some/path', {}, config=config) n.components = [mock_component_1, mock_component_2] n.run(provider) @@ -34,7 +36,9 @@ def test_stop(self): mock_component_1 = mock.Mock() mock_component_2 = mock.Mock() - n = Nulecule('some-id', '0.0.2', {}, [], 'some/path') + config = Config(answers={}) + + n = Nulecule('some-id', '0.0.2', {}, [], 'some/path', config=config) n.components = [mock_component_1, mock_component_2] n.stop(provider) @@ -50,70 +54,59 @@ def test_load_config_without_specified_provider(self): """ Test Nulecule load_config without specifying a provider. """ - config = {'general': {}, 'group1': {'a': 'b'}} - mock_component_1 = mock.Mock() - mock_component_1.config = { - 'group1': {'a': 'c', 'k': 'v'}, - 'group2': {'1': '2'} - } + config = Config(answers={}) - n = Nulecule(id='some-id', specversion='0.0.2', metadata={}, graph=[], basepath='some/path') - n.components = [mock_component_1] - n.load_config(config) + params = [ + { + "name": "key1", + "default": "val1", + }, + { + "name": "key3", + "default": "val3" + } + ] - self.assertEqual(n.config, { - 'general': {'provider': 'kubernetes'}, - 'group1': {'a': 'b', 'k': 'v'}, - 'group2': {'1': '2'} - }) + graph = [ + { + "name": "component1", + "params": [ + { + "name": "key1", + }, + { + "name": "key2", + "default": "val2" + } + ], + "artifacts": [] + } + ] - def test_load_config_with_defaultprovider(self): - """ - Test Nulecule load_config with default provider specified - in global params in Nulecule spec. - """ - config = {'general': {}, 'group1': {'a': 'b'}} - mock_component_1 = mock.Mock() - mock_component_1.config = { - 'group1': {'a': 'c', 'k': 'v'}, - 'group2': {'1': '2'} - } - - n = Nulecule(id='some-id', specversion='0.0.2', metadata={}, graph=[], - basepath='some/path', - params=[{'name': 'provider', 'default': 'some-provider'}]) - n.components = [mock_component_1] + n = Nulecule(id='some-id', specversion='0.0.2', metadata={}, + graph=graph, params=params, basepath='some/path', + config=config) + n.load_components() n.load_config(config) - self.assertEqual(n.config, { - 'general': {'provider': 'some-provider'}, - 'group1': {'a': 'b', 'k': 'v'}, - 'group2': {'1': '2'} + self.assertEqual(n.config.runtime_answers(), { + 'general': { + 'namespace': 'default', + 'provider': 'kubernetes', + 'key1': 'val1', + 'key3': 'val3' + }, + 'component1': { + 'key2': 'val2', + 'key1': 'val1' + } }) - def test_load_config_with_defaultprovider_overridden_by_provider_in_answers(self): - """ - Test Nulecule load_config with default provider specified - in global params in Nulecule spec, but overridden in answers config. - """ - config = {'general': {'provider': 'new-provider'}, - 'group1': {'a': 'b'}} - mock_component_1 = mock.Mock() - mock_component_1.config = { - 'group1': {'a': 'c', 'k': 'v'}, - 'group2': {'1': '2'} - } - - n = Nulecule(id='some-id', specversion='0.0.2', metadata={}, graph=[], - basepath='some/path', - params=[{'name': 'provider', 'default': 'some-provider'}]) - n.components = [mock_component_1] - n.load_config(config) - - self.assertEqual(n.config, { - 'general': {'provider': 'new-provider'}, - 'group1': {'a': 'b', 'k': 'v'}, - 'group2': {'1': '2'} + self.assertEqual(n.components[0].config.context(), { + 'key3': 'val3', + 'key2': 'val2', + 'key1': 'val1', + 'provider': 'kubernetes' }) @@ -137,15 +130,17 @@ def test_load_components(self, MockNuleculeComponent): } ] - n = Nulecule('some-id', '0.0.2', graph, 'some/path', {}) + config = Config(answers={}) + + n = Nulecule('some-id', '0.0.2', graph, 'some/path', config=config) n.load_components() MockNuleculeComponent.assert_any_call( graph[0]['name'], n.basepath, 'somecontainer', - graph[0]['params'], None, {}) + graph[0]['params'], None, config) MockNuleculeComponent.assert_any_call( graph[1]['name'], n.basepath, None, - graph[1].get('params'), graph[1].get('artifacts'), {}) + graph[1].get('params'), graph[1].get('artifacts'), config) class TestNuleculeRender(unittest.TestCase): diff --git a/tests/units/nulecule/test_nulecule_component.py b/tests/units/nulecule/test_nulecule_component.py index 28b98774..d84fb999 100644 --- a/tests/units/nulecule/test_nulecule_component.py +++ b/tests/units/nulecule/test_nulecule_component.py @@ -136,19 +136,18 @@ def test_load_config_local_app(self): 'general': {'a': 'b', 'key2': 'val2'}, 'some-app': {'key1': 'val1'} } - config = Config('some-app', answers=initial_config) + conf = Config('some-app', answers=initial_config) nc = NuleculeComponent('some-app', 'some/path', - params=params) - nc.load_config(config=config) - - self.assertEqual(nc.config.runtime_answers(), { - 'general': {'a': 'b', 'key2': 'val2'}, + params=params, config=conf) + nc.load_config() + runtime_answers = nc.config.runtime_answers() + self.assertEqual(runtime_answers, { + 'general': {'a': 'b', 'key2': 'val2', 'provider': 'kubernetes', 'namespace': 'default'}, 'some-app': {'key1': 'val1', 'key2': 'val2'} }) - @mock.patch('atomicapp.nulecule.base.NuleculeComponent.merge_config') - def test_load_config_external_app(self, mock_merge_config): + def test_load_config_external_app(self): """Test load config for external app""" mock_nulecule = mock.Mock( name='nulecule',