test_init.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """Test init"""
  2. import pytest
  3. @pytest.mark.parametrize(
  4. 'alt_work, repo_present, force', [
  5. (False, False, False),
  6. (True, False, False),
  7. (False, True, False),
  8. (False, True, True),
  9. (True, True, True),
  10. ], ids=[
  11. 'simple',
  12. '-w',
  13. 'existing repo',
  14. '-f',
  15. '-w & -f',
  16. ])
  17. @pytest.mark.usefixtures('ds1_work_copy')
  18. def test_init(
  19. runner, yadm_y, paths, repo_config, alt_work, repo_present, force):
  20. """Test init
  21. Repos should have attribs:
  22. - 0600 permissions
  23. - not bare
  24. - worktree = $HOME
  25. - showUntrackedFiles = no
  26. - yadm.managed = true
  27. """
  28. # these tests will assume this for $HOME
  29. home = str(paths.root.mkdir('HOME'))
  30. # ds1_work_copy comes WITH an empty repo dir present.
  31. old_repo = paths.repo.join('old_repo')
  32. if repo_present:
  33. # Let's put some data in it, so we can confirm that data is gone when
  34. # forced to be overwritten.
  35. old_repo.write('old repo data')
  36. assert old_repo.isfile()
  37. else:
  38. paths.repo.remove()
  39. # command args
  40. args = ['init']
  41. if alt_work:
  42. args.extend(['-w', paths.work])
  43. if force:
  44. args.append('-f')
  45. # run init
  46. run = runner(yadm_y(*args), env={'HOME': home})
  47. assert run.err == ''
  48. if repo_present and not force:
  49. assert run.failure
  50. assert 'repo already exists' in run.out
  51. assert old_repo.isfile(), 'Missing original repo'
  52. else:
  53. assert run.success
  54. assert 'Initialized empty shared Git repository' in run.out
  55. if repo_present:
  56. assert not old_repo.isfile(), 'Original repo still exists'
  57. if alt_work:
  58. assert repo_config('core.worktree') == paths.work
  59. else:
  60. assert repo_config('core.worktree') == home
  61. # uniform repo assertions
  62. assert oct(paths.repo.stat().mode).endswith('00'), (
  63. 'Repo is not secure')
  64. assert repo_config('core.bare') == 'false'
  65. assert repo_config('status.showUntrackedFiles') == 'no'
  66. assert repo_config('yadm.managed') == 'true'