From eaed231a5fe8706a71f44871a32e813d4b91c777 Mon Sep 17 00:00:00 2001 From: Aidan Gallagher Date: Tue, 18 Jun 2024 13:32:43 +0100 Subject: [PATCH] Unit Test: Fix unit tests which were broken in previous 2 commits --- debpic/python/debpic_test.py | 17 ++++++++++++++--- debpic/python/run.py | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/debpic/python/debpic_test.py b/debpic/python/debpic_test.py index 541207a..1105bc8 100644 --- a/debpic/python/debpic_test.py +++ b/debpic/python/debpic_test.py @@ -15,6 +15,11 @@ def setup_method(self, test_method): def run_mock(command, **kwargs): self.cli_commands.append(command) + + if command == "gpgconf --list-dirs agent-socket": + return "/run/user/1000/gnupg/S.gpg-agent" + elif command == "gpgconf --list-dir homedir": + return "/home/debpic_user/.gnupg" return "test" common.run = run_mock @@ -56,19 +61,25 @@ def test_build_image(self): def test_run_container(self): run.run_container("test_name") + assert self.cli_commands.pop(0) == "gpgconf --list-dirs agent-socket" + assert self.cli_commands.pop(0) == "gpgconf --list-dir homedir" assert ( self.cli_commands.pop(0) - == "docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS=\"\" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && dpkg-buildpackage && mv-debs && dpkg-buildpackage --target=clean'" + == """docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --mount type=bind,src=/run/user/1000/gnupg/S.gpg-agent,dst=/home/docker/.gnupg/S.gpg-agent,readonly --mount type=bind,src=/home/debpic_user/.gnupg/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly --mount type=bind,src=/home/debpic_user/.gnupg/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly --mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && dpkg-buildpackage && mv-debs && dpkg-buildpackage --target=clean'""" ) run.run_container("test_name", "echo I'm a test command") + assert self.cli_commands.pop(0) == "gpgconf --list-dirs agent-socket" + assert self.cli_commands.pop(0) == "gpgconf --list-dir homedir" assert ( self.cli_commands.pop(0) - == "docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS=\"\" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && echo I'm a test command'" + == "docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --mount type=bind,src=/run/user/1000/gnupg/S.gpg-agent,dst=/home/docker/.gnupg/S.gpg-agent,readonly --mount type=bind,src=/home/debpic_user/.gnupg/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly --mount type=bind,src=/home/debpic_user/.gnupg/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly --mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS=\"\" test_name /bin/bash -c 'if [[ -x /usr/bin/hook ]]; then /usr/bin/hook; fi && echo I'm a test command'" ) run.run_container("test_name", "", "", "--interactive") + assert self.cli_commands.pop(0) == "gpgconf --list-dirs agent-socket" + assert self.cli_commands.pop(0) == "gpgconf --list-dir homedir" assert ( self.cli_commands.pop(0) - == 'docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" --interactive test_name ' + == 'docker run --mount type=bind,src=${PWD},dst=/workspaces/code --mount type=volume,src=debpic_cache,dst=/home/docker/.cache --mount type=bind,src=/run/user/1000/gnupg/S.gpg-agent,dst=/home/docker/.gnupg/S.gpg-agent,readonly --mount type=bind,src=/home/debpic_user/.gnupg/pubring.kbx,dst=/home/docker/.gnupg/pubring.kbx,readonly --mount type=bind,src=/home/debpic_user/.gnupg/trustdb.gpg,dst=/home/docker/.gnupg/trustdb.gpg,readonly --mount type=bind,src=$HOME/.config,dst=/home/docker/.config,readonly --user 1000:$(id -g 1000) --network host --tty --rm --env DEB_BUILD_OPTIONS="" --interactive test_name ' ) diff --git a/debpic/python/run.py b/debpic/python/run.py index 10e3b41..922c3c6 100644 --- a/debpic/python/run.py +++ b/debpic/python/run.py @@ -36,8 +36,8 @@ def run_container( deb_build_options = os.environ.get("DEB_BUILD_OPTIONS", "") # TODO: If the host doesn't have gpg installed then skip this. - gpg_home = common.run("gpgconf --list-dir homedir").strip() gpg_socket = common.run("gpgconf --list-dirs agent-socket").strip() + gpg_home = common.run("gpgconf --list-dir homedir").strip() run_cmd = f"""\ docker run