2 # Copyright (c) 2019 Cloudify Platform Ltd. All rights reserved
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # * See the License for the specific language governing permissions and
14 # * limitations under the License.
18 from helm_sdk.exceptions import CloudifyHelmSDKError
19 from helm_sdk.utils import (
21 prepare_set_parameters,
22 validate_no_collisions_between_params_and_flags)
25 class TestUtils(unittest.TestCase):
27 def test_prepare_parameter(self):
28 param_dict = {'name': 'param1'}
29 self.assertEqual(prepare_parameter(param_dict), '--param1')
30 param_dict.update({'value': 'value1'})
31 self.assertEqual(prepare_parameter(param_dict), '--param1=value1')
33 def test_prepare_set_parameters(self):
34 set_no_val = [{'name': 'x'}]
35 with self.assertRaisesRegexp(
37 "\"set\" parameter name or value is missing"):
38 prepare_set_parameters(set_no_val)
40 with self.assertRaisesRegexp(
42 "\"set\" parameter name or value is missing"):
43 set_no_name = [{'value': 'y'}]
44 prepare_set_parameters(set_no_name)
45 # Now set_dict_no_val is a valid set parameter dictionary
46 valid_set_list = [{'name': 'x', 'value': 'y'}]
47 self.assertEqual(prepare_set_parameters(valid_set_list),
50 def test_validate_no_collisions_between_params_and_flags(self):
51 fake_flags = [{'name': 'kube-apiserver', 'value': 'https://0.0.0.0'}]
52 with self.assertRaisesRegexp(CloudifyHelmSDKError,
53 "Please do not pass"):
54 validate_no_collisions_between_params_and_flags(fake_flags)
55 fake_flags = [{'name': 'debug'}]
57 validate_no_collisions_between_params_and_flags(fake_flags),
61 validate_no_collisions_between_params_and_flags(fake_flags),