Skip to content

Commit

Permalink
Unit Test: Fix unit tests which were broken in previous 2 commits
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan-gallagher committed Jun 18, 2024
1 parent 9f86b57 commit eaed231
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions debpic/python/debpic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 '
)
2 changes: 1 addition & 1 deletion debpic/python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eaed231

Please sign in to comment.