From f4e79501f1be1394873042dd65beda49e869afb8 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sat, 10 Oct 2020 17:24:57 +0200 Subject: test(cli): add test for job artifacts download --- tools/functional/cli/test_cli_artifacts.py | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tools/functional/cli/test_cli_artifacts.py (limited to 'tools/functional/cli') diff --git a/tools/functional/cli/test_cli_artifacts.py b/tools/functional/cli/test_cli_artifacts.py new file mode 100644 index 0000000..27d5d74 --- /dev/null +++ b/tools/functional/cli/test_cli_artifacts.py @@ -0,0 +1,52 @@ +import subprocess +import sys +import textwrap +import time +from io import BytesIO +from zipfile import is_zipfile + +import pytest + + +content = textwrap.dedent( + """\ + test-artifact: + script: echo "test" > artifact.txt + artifacts: + untracked: true + """ +) +data = { + "file_path": ".gitlab-ci.yml", + "branch": "master", + "content": content, + "commit_message": "Initial commit", +} + + +@pytest.mark.skipif(sys.version_info < (3, 8), reason="I am the walrus") +def test_cli_artifacts(capsysbinary, gitlab_config, gitlab_runner, project): + project.files.create(data) + + while not (jobs := project.jobs.list(scope="success")): + time.sleep(0.5) + + job = project.jobs.get(jobs[0].id) + cmd = [ + "gitlab", + "--config-file", + gitlab_config, + "project-job", + "artifacts", + "--id", + str(job.id), + "--project-id", + str(project.id), + ] + + with capsysbinary.disabled(): + artifacts = subprocess.check_output(cmd) + assert isinstance(artifacts, bytes) + + artifacts_zip = BytesIO(artifacts) + assert is_zipfile(artifacts_zip) -- cgit v1.2.1