def test_00_simple_resolve_path(self): path_list = k8s_config_json_patch.path_to_list('/metadata/name') value, context, key, matched_path, unmatched_path = k8s_config_json_patch.resolve_path( deployment, path_list) self.assertEqual(value, 'myapp') self.assertEqual(context, deployment['metadata']) self.assertEqual(key, 'name') self.assertEqual(matched_path, ['metadata', 'name']) self.assertEqual(unmatched_path, [])
def test_05_unmatched_resolve_path(self): path_list = k8s_config_json_patch.path_to_list('/metadata/labels/name') value, context, key, matched_path, unmatched_path = k8s_config_json_patch.resolve_path( deployment, path_list) self.assertEqual(value, None) self.assertEqual(context, deployment['metadata']) self.assertEqual(key, 'labels') self.assertEqual(matched_path, ['metadata']) self.assertEqual(unmatched_path, ['labels', 'name'])
def test_06_unmatched_resolve_path(self): path_list = k8s_config_json_patch.path_to_list( "/spec/template/spec/containers/[?name='nomatch']") value, context, key, matched_path, unmatched_path = k8s_config_json_patch.resolve_path( deployment, path_list) self.assertEqual(value, None) self.assertEqual(context, deployment['spec']['template']['spec']['containers']) self.assertEqual(key, "[?name='nomatch']") self.assertEqual(matched_path, ['spec', 'template', 'spec', 'containers']) self.assertEqual(unmatched_path, ["[?name='nomatch']"])
def test_02_deep_resolve_path(self): path_list = k8s_config_json_patch.path_to_list( '/spec/template/spec/containers/0/env/0/value') value, context, key, matched_path, unmatched_path = k8s_config_json_patch.resolve_path( deployment, path_list) self.assertEqual(value, 'value1') self.assertEqual( context, deployment['spec']['template']['spec']['containers'][0]['env'][0]) self.assertEqual(key, 'value') self.assertEqual(matched_path, [ 'spec', 'template', 'spec', 'containers', '0', 'env', '0', 'value' ]) self.assertEqual(unmatched_path, [])
def test_03_query_resolve_path(self): path_list = k8s_config_json_patch.path_to_list( "/spec/template/spec/containers/[?name='app']/env/[?name='VAR2']") value, context, key, matched_path, unmatched_path = k8s_config_json_patch.resolve_path( deployment, path_list) self.assertEqual(value, {'name': 'VAR2', 'value': 'value2'}) self.assertEqual( context, deployment['spec']['template']['spec']['containers'][0]['env']) self.assertEqual(key, 1) self.assertEqual( matched_path, ['spec', 'template', 'spec', 'containers', '0', 'env', '1']) self.assertEqual(unmatched_path, [])
def test_07_unmatched_resolve_path(self): path_list = k8s_config_json_patch.path_to_list( "/spec/template/spec/containers/[?name='app']/env/[?name='NOSUCH']/value" ) value, context, key, matched_path, unmatched_path = k8s_config_json_patch.resolve_path( deployment, path_list) self.assertEqual(value, None) self.assertEqual( context, deployment['spec']['template']['spec']['containers'][0]['env']) self.assertEqual(key, "[?name='NOSUCH']") self.assertEqual( matched_path, ['spec', 'template', 'spec', 'containers', '0', 'env']) self.assertEqual(unmatched_path, ["[?name='NOSUCH']", 'value'])