From 7c9f3c613b6612af54f340e4f0e3266a83f35044 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 18 Sep 2020 09:39:50 -0600 Subject: [PATCH] add a test for nested repo checkout --- test/test_sys_checkout.py | 95 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/test/test_sys_checkout.py b/test/test_sys_checkout.py index ff9d5024d..c9e07cbdb 100644 --- a/test/test_sys_checkout.py +++ b/test/test_sys_checkout.py @@ -85,6 +85,8 @@ CFG_SUB_NAME = 'sub-externals.cfg' README_NAME = 'readme.txt' REMOTE_BRANCH_FEATURE2 = 'feature2' +NESTED_NAME = ['./fred', './fred/wilma', './fred/wilma/barney'] + SVN_TEST_REPO = 'https://github.com/escomp/cesm' @@ -160,6 +162,23 @@ def container_simple_required(self, dest_dir): self.write_config(dest_dir) + def container_nested_required(self, dest_dir, order=[0,1,2]): + """Create a container externals file with only simple externals. + + """ + self.create_config() + self.create_section(SIMPLE_REPO_NAME, 'simp_tag', nested=True, + tag='tag1', path=NESTED_NAME[order[0]]) + + self.create_section(SIMPLE_REPO_NAME, 'simp_branch', nested=True, + branch=REMOTE_BRANCH_FEATURE2, path=NESTED_NAME[order[1]]) + + self.create_section(SIMPLE_REPO_NAME, 'simp_hash', nested=True, + ref_hash='60b1cc1a38d63',path=NESTED_NAME[order[2]]) + + self.write_config(dest_dir) + + def container_simple_optional(self, dest_dir): """Create a container externals file with optional simple externals @@ -261,7 +280,7 @@ def create_metadata(self): def create_section(self, repo_type, name, tag='', branch='', ref_hash='', required=True, path=EXTERNALS_NAME, externals='', repo_path=None, from_submodule=False, - sparse=''): + sparse='', nested=False): # pylint: disable=too-many-branches """Create a config section with autofilling some items and handling optional items. @@ -270,8 +289,11 @@ def create_section(self, repo_type, name, tag='', branch='', # pylint: disable=R0913 self._config.add_section(name) if not from_submodule: - self._config.set(name, ExternalsDescription.PATH, - os.path.join(path, name)) + if nested: + self._config.set(name, ExternalsDescription.PATH, path) + else: + self._config.set(name, ExternalsDescription.PATH, + os.path.join(path, name)) self._config.set(name, ExternalsDescription.PROTOCOL, ExternalsDescription.PROTOCOL_GIT) @@ -671,10 +693,16 @@ def _check_simple_tag_empty(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_tag'.format(directory) self._check_generic_empty_default_required(tree, name) + def _check_nested_tag_empty(self, tree, name=EXTERNALS_NAME): + self._check_generic_empty_default_required(tree, name) + def _check_simple_tag_ok(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_tag'.format(directory) self._check_generic_ok_clean_required(tree, name) + def _check_nested_tag_ok(self, tree, name=EXTERNALS_NAME): + self._check_generic_ok_clean_required(tree, name) + def _check_simple_tag_dirty(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_tag'.format(directory) self._check_generic_ok_dirty_required(tree, name) @@ -687,10 +715,16 @@ def _check_simple_branch_empty(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_branch'.format(directory) self._check_generic_empty_default_required(tree, name) + def _check_nested_branch_empty(self, tree, name=EXTERNALS_NAME): + self._check_generic_empty_default_required(tree, name) + def _check_simple_branch_ok(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_branch'.format(directory) self._check_generic_ok_clean_required(tree, name) + def _check_nested_branch_ok(self, tree, name=EXTERNALS_NAME): + self._check_generic_ok_clean_required(tree, name) + def _check_simple_branch_modified(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_branch'.format(directory) self._check_generic_modified_ok_required(tree, name) @@ -699,10 +733,16 @@ def _check_simple_hash_empty(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_hash'.format(directory) self._check_generic_empty_default_required(tree, name) + def _check_nested_hash_empty(self, tree, name=EXTERNALS_NAME): + self._check_generic_empty_default_required(tree, name) + def _check_simple_hash_ok(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_hash'.format(directory) self._check_generic_ok_clean_required(tree, name) + def _check_nested_hash_ok(self, tree, name=EXTERNALS_NAME): + self._check_generic_ok_clean_required(tree, name) + def _check_simple_hash_modified(self, tree, directory=EXTERNALS_NAME): name = './{0}/simp_hash'.format(directory) self._check_generic_modified_ok_required(tree, name) @@ -754,6 +794,12 @@ def _check_container_simple_required_pre_checkout(self, overall, tree): self._check_simple_branch_empty(tree) self._check_simple_hash_empty(tree) + def _check_container_nested_required_pre_checkout(self, overall, tree, order=[0,1,2]): + self.assertEqual(overall, 0) + self._check_nested_tag_empty(tree, name=NESTED_NAME[order[0]]) + self._check_nested_branch_empty(tree, name=NESTED_NAME[order[1]]) + self._check_nested_hash_empty(tree, name=NESTED_NAME[order[2]]) + def _check_container_simple_required_checkout(self, overall, tree): # Note, this is the internal tree status just before checkout self.assertEqual(overall, 0) @@ -761,12 +807,25 @@ def _check_container_simple_required_checkout(self, overall, tree): self._check_simple_branch_empty(tree) self._check_simple_hash_empty(tree) + def _check_container_nested_required_checkout(self, overall, tree, order=[0,1,2]): + # Note, this is the internal tree status just before checkout + self.assertEqual(overall, 0) + self._check_nested_tag_empty(tree, name=NESTED_NAME[order[0]]) + self._check_nested_branch_empty(tree, name=NESTED_NAME[order[1]]) + self._check_nested_hash_empty(tree, name=NESTED_NAME[order[2]]) + def _check_container_simple_required_post_checkout(self, overall, tree): self.assertEqual(overall, 0) self._check_simple_tag_ok(tree) self._check_simple_branch_ok(tree) self._check_simple_hash_ok(tree) + def _check_container_nested_required_post_checkout(self, overall, tree, order=[0,1,2]): + self.assertEqual(overall, 0) + self._check_nested_tag_ok(tree, name=NESTED_NAME[order[0]]) + self._check_nested_branch_ok(tree, name=NESTED_NAME[order[1]]) + self._check_nested_hash_ok(tree, name=NESTED_NAME[order[2]]) + def _check_container_simple_required_out_of_sync(self, overall, tree): self.assertEqual(overall, 0) self._check_simple_tag_modified(tree) @@ -964,6 +1023,36 @@ def test_container_simple_required(self): self.status_args) self._check_container_simple_required_post_checkout(overall, tree) + def test_container_nested_required(self): + """Verify that a container with nested subrepos + generates the correct initial status. + Tests over all possible permutations + """ + + orders = [[0,1,2], [1,2,0], [2,0,1], [0,2,1], [2,1,0], [1,0,2]] + for n, order in enumerate(orders): + # create repo + dest_dir=os.path.join(os.environ[MANIC_TEST_TMP_REPO_ROOT], + self._test_id,"test"+str(n)) + under_test_dir = self.setup_test_repo(CONTAINER_REPO_NAME, + dest_dir_in=dest_dir) + self._generator.container_nested_required(under_test_dir, order=order) + + # status of empty repo + overall, tree = self.execute_cmd_in_dir(under_test_dir, + self.status_args) + self._check_container_nested_required_pre_checkout(overall, tree, order=order) + + # checkout + overall, tree = self.execute_cmd_in_dir(under_test_dir, + self.checkout_args) + self._check_container_nested_required_checkout(overall, tree, order=order) + + # status clean checked out + overall, tree = self.execute_cmd_in_dir(under_test_dir, + self.status_args) + self._check_container_nested_required_post_checkout(overall, tree, order=order) + def test_container_simple_optional(self): """Verify that container with an optional simple subrepos generates the correct initial status.