From 1af722eb494d1173bfcc9aec1cdb8aab93cf6fc8 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Tue, 10 Nov 2015 13:37:51 +1000 Subject: [PATCH] Add a test case for load_config This is just a basic test to make sure loading from file works. Change-Id: I074f36023ac4198c436fcee1668d32f9d1f0e61b --- tests/test_set_config.py | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test_set_config.py diff --git a/tests/test_set_config.py b/tests/test_set_config.py new file mode 100644 index 0000000000..c1e7f79273 --- /dev/null +++ b/tests/test_set_config.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import imp +import json +import mock +import os.path +import sys + +from oslotest import base + +# nasty: to import set_config (not a part of the kolla package) +this_dir = os.path.dirname(sys.modules[__name__].__file__) +set_configs_file = os.path.abspath( + os.path.join(this_dir, '..', + 'docker', 'base', 'set_configs.py')) + +set_configs = imp.load_source('set_configs', set_configs_file) + + +class LoadFromFile(base.BaseTestCase): + + def test_load_ok(self): + in_config = json.dumps({'command': '/bin/true', + 'config_files': {}}) + + mo = mock.mock_open(read_data=in_config) + with mock.patch.object(set_configs, 'open', mo): + set_configs.load_config() + self.assertEqual([ + mock.call('/var/lib/kolla/config_files/config.json'), + mock.call().__enter__(), + mock.call().read(), + mock.call().__exit__(None, None, None), + mock.call('/run_command', 'w+'), + mock.call().__enter__(), + mock.call().write(u'/bin/true'), + mock.call().__exit__(None, None, None)], mo.mock_calls)