From 0f9756e7395d49c8d75ac8796feeac846814fb22 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 10 Jun 2023 15:17:18 -0700 Subject: [PATCH] Fix failing test and add "bootstrap" action to CLI reference docs (#697). --- borgmatic/actions/create.py | 4 ++-- borgmatic/commands/arguments.py | 2 +- docs/Dockerfile | 4 ++-- tests/unit/actions/test_create.py | 11 +++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/borgmatic/actions/create.py b/borgmatic/actions/create.py index 4d83634..1bacf73 100644 --- a/borgmatic/actions/create.py +++ b/borgmatic/actions/create.py @@ -8,11 +8,11 @@ except ModuleNotFoundError: # pragma: nocover import importlib.metadata as importlib_metadata import borgmatic.borg.create +import borgmatic.borg.state import borgmatic.config.validate import borgmatic.hooks.command import borgmatic.hooks.dispatch import borgmatic.hooks.dump -from borgmatic.borg.state import DEFAULT_BORGMATIC_SOURCE_DIRECTORY logger = logging.getLogger(__name__) @@ -26,7 +26,7 @@ def create_borgmatic_manifest(location, config_paths, dry_run): return borgmatic_source_directory = location.get( - 'borgmatic_source_directory', DEFAULT_BORGMATIC_SOURCE_DIRECTORY + 'borgmatic_source_directory', borgmatic.borg.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY ) borgmatic_manifest_path = os.path.expanduser( diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index ca4c2db..30ac3f9 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -632,7 +632,7 @@ def make_parsers(): 'bootstrap', aliases=SUBPARSER_ALIASES['config_bootstrap'], help='Extract the config files used to create a borgmatic repository', - description='Extract config files that were used to create a borgmatic repository during the "create" operation', + description='Extract config files that were used to create a borgmatic repository during the "create" action', add_help=False, ) config_bootstrap_group = config_bootstrap_parser.add_argument_group( diff --git a/docs/Dockerfile b/docs/Dockerfile index b612596..750d4e5 100644 --- a/docs/Dockerfile +++ b/docs/Dockerfile @@ -4,9 +4,9 @@ COPY . /app RUN apk add --no-cache py3-pip py3-ruamel.yaml py3-ruamel.yaml.clib RUN pip install --no-cache /app && generate-borgmatic-config && chmod +r /etc/borgmatic/config.yaml RUN borgmatic --help > /command-line.txt \ - && for action in rcreate transfer create prune compact check extract export-tar mount umount restore rlist list rinfo info break-lock borg; do \ + && for action in rcreate transfer create prune compact check extract config "config bootstrap" export-tar mount umount restore rlist list rinfo info break-lock borg; do \ echo -e "\n--------------------------------------------------------------------------------\n" >> /command-line.txt \ - && borgmatic "$action" --help >> /command-line.txt; done + && borgmatic $action --help >> /command-line.txt; done FROM docker.io/node:19.5.0-alpine as html diff --git a/tests/unit/actions/test_create.py b/tests/unit/actions/test_create.py index 7eeca8b..de94fd7 100644 --- a/tests/unit/actions/test_create.py +++ b/tests/unit/actions/test_create.py @@ -111,10 +111,21 @@ def test_run_create_bails_if_repository_does_not_match(): def test_create_borgmatic_manifest_creates_manifest_file(): + flexmock(module.os.path).should_receive('join').with_args( + module.borgmatic.borg.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY, 'bootstrap', 'manifest.json' + ).and_return('/home/user/.borgmatic/bootstrap/manifest.json') flexmock(module.os.path).should_receive('exists').and_return(False) flexmock(module.os).should_receive('makedirs').and_return(True) flexmock(module.importlib_metadata).should_receive('version').and_return('1.0.0') + flexmock(sys.modules['builtins']).should_receive('open').with_args( + '/home/user/.borgmatic/bootstrap/manifest.json', 'w' + ).and_return( + flexmock( + __enter__=lambda *args: flexmock(write=lambda *args: None, close=lambda *args: None), + __exit__=lambda *args: None, + ) + ) flexmock(module.json).should_receive('dump').and_return(True).once() module.create_borgmatic_manifest({}, 'test.yaml', False)