def test_post_clone_hook(self) -> None: edenrc = os.path.join(self.home_dir, ".edenrc") hooks_dir = os.path.join(self.tmp_dir, "the_hooks") os.mkdir(hooks_dir) with open(edenrc, "w") as f: f.write( """\ [repository {repo_name}] path = {repo_path} type = {repo_type} hooks = {hooks_dir} """.format( repo_name=repo_name, repo_path=self.repo.get_canonical_root(), repo_type=self.repo.get_type(), hooks_dir=hooks_dir, ) ) # Create a post-clone hook that has a visible side-effect every time it # is run so we can verify that it is only run once. hg_post_clone_hook = os.path.join(hooks_dir, "post-clone") scratch_file = os.path.join(self.tmp_dir, "scratch_file") with open(scratch_file, "w") as f: f.write("ok") with open(hg_post_clone_hook, "w") as f: f.write( """\ #!/bin/bash CONTENTS=`cat "{scratch_file}"` echo -n "$1" >> "{scratch_file}" """.format( scratch_file=scratch_file ) ) os.chmod(hg_post_clone_hook, stat.S_IRWXU) # Verify that the hook gets run as part of `eden clone`. self.assertEqual("ok", util.read_all(scratch_file)) tmp = self._new_tmp_dir() self.eden.clone(repo_name, tmp) new_contents = "ok" + self.repo.get_type() self.assertEqual(new_contents, util.read_all(scratch_file)) # Restart Eden and verify that post-clone is NOT run again. self.eden.shutdown() self.eden.start() self.assertEqual(new_contents, util.read_all(scratch_file))
def test_custom_not_mounted_readme(self) -> None: """Test that "eden clone" creates a README file in the mount point directory telling users what to do if their checkout is not currently mounted. """ # Write a custom readme file in our etc config directory custom_readme_text = "If this is broken bug [email protected]\n" with open(os.path.join(self.etc_eden_dir, "NOT_MOUNTED_README.txt"), "w") as f: f.write(custom_readme_text) # Perform a clone new_mount = self._new_tmp_dir() readme_path = os.path.join(new_mount, "README_EDEN.txt") self.eden.run_cmd("clone", self.repo.path, new_mount) self.assertEqual("hola\n", util.read_all(os.path.join(new_mount, "hello"))) self.assertFalse(os.path.exists(readme_path)) # Now unmount the checkout and make sure we see the readme self.eden.run_cmd("unmount", new_mount) self.assertFalse(os.path.exists(os.path.join(new_mount, "hello"))) self.assertEqual(custom_readme_text, util.read_all(readme_path))
def test_post_clone_hook(self): edenrc = os.path.join(os.environ['HOME'], '.edenrc') hooks_dir = os.path.join(self.tmp_dir, 'the_hooks') os.mkdir(hooks_dir) with open(edenrc, 'w') as f: f.write('''\ [repository {repo_name}] path = {repo_path} type = {repo_type} hooks = {hooks_dir} '''.format(repo_name=repo_name, repo_path=self.repo.get_canonical_root(), repo_type=self.repo.get_type(), hooks_dir=hooks_dir)) # Create a post-clone hook that has a visible side-effect every time it # is run so we can verify that it is only run once. hg_post_clone_hook = os.path.join(hooks_dir, 'post-clone') scratch_file = os.path.join(self.tmp_dir, 'scratch_file') with open(scratch_file, 'w') as f: f.write('ok') with open(hg_post_clone_hook, 'w') as f: f.write('''\ #!/bin/bash CONTENTS=`cat "{scratch_file}"` echo -n "$1" >> "{scratch_file}" '''.format(scratch_file=scratch_file)) os.chmod(hg_post_clone_hook, stat.S_IRWXU) # Verify that the hook gets run as part of `eden clone`. self.assertEqual('ok', util.read_all(scratch_file)) tmp = self._new_tmp_dir() self.eden.clone(repo_name, tmp) new_contents = 'ok' + self.repo.get_type() self.assertEqual(new_contents, util.read_all(scratch_file)) # Restart Eden and verify that post-clone is NOT run again. self.eden.shutdown() self.eden.start() self.assertEqual(new_contents, util.read_all(scratch_file))
def test_clone_should_start_daemon(self) -> None: # Shut down Eden. self.assertTrue(self.eden.is_healthy()) self.eden.shutdown() self.assertFalse(self.eden.is_healthy()) # Check `eden list`. list_output = self.eden.list_cmd() self.assertEqual( {self.mount: self.eden.CLIENT_INACTIVE}, list_output, msg="Eden should have one mount.", ) extra_daemon_args = self.eden.get_extra_daemon_args() # Verify that clone starts the daemon. tmp = self.make_temporary_directory() clone_output = self.eden.run_cmd( "clone", "--daemon-binary", FindExe.EDEN_DAEMON, self.repo.path, tmp, "--daemon-args", *extra_daemon_args, ) self.assertIn("Starting edenfs", clone_output) self.assertTrue(self.eden.is_healthy(), msg="clone should start Eden.") mount_points = { self.mount: self.eden.CLIENT_ACTIVE, tmp: self.eden.CLIENT_ACTIVE, } self.assertEqual(mount_points, self.eden.list_cmd(), msg="Eden should have two mounts.") self.assertEqual( "hola\n", util.read_all(bytes(os.path.join(tmp, "hello"), "utf-8")))
def test_clone_should_start_daemon(self): # Shut down Eden. self.assertTrue(self.eden.is_healthy()) self.eden.shutdown() self.assertFalse(self.eden.is_healthy()) # Check `eden list`. list_output = self.eden.list_cmd() self.assertEqual({self.mount: self.eden.CLIENT_INACTIVE}, list_output, msg='Eden should have one mount.') # Verify that clone starts the daemon. tmp = self._new_tmp_dir() self.eden.run_cmd('clone', self.repo.path, tmp) self.assertTrue(self.eden.is_healthy(), msg='clone should start Eden.') mount_points = { self.mount: self.eden.CLIENT_ACTIVE, tmp: self.eden.CLIENT_ACTIVE, } self.assertEqual(mount_points, self.eden.list_cmd(), msg='Eden should have two mounts.') self.assertEqual('hola\n', util.read_all(os.path.join(tmp, 'hello')))