From 9baca1fe90a22acfa5b357effd3691367d41d366 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 28 Feb 2024 15:09:11 +0100 Subject: [PATCH] stages: add small unit test for the gzip stage --- stages/test/test_gzip.py | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 stages/test/test_gzip.py diff --git a/stages/test/test_gzip.py b/stages/test/test_gzip.py new file mode 100644 index 00000000..02b01051 --- /dev/null +++ b/stages/test/test_gzip.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +from unittest.mock import patch + +import pytest + +STAGE_NAME = "org.osbuild.gzip" + + +@pytest.mark.parametrize("test_options,expected_level", [ + # our default + ({}, "-1"), + # custom settings + ({"level": "1"}, "-1"), + ({"level": "6"}, "-6"), + ({"level": "9"}, "-9"), +]) +@patch("subprocess.run") +def test_gzip_compression_default_to_level1(mocked_run, tmp_path, stage_module, test_options, expected_level): + inp = { + "file": { + "path": "/input/file/path", + "data": { + "files": { + "hash:value": "some-file", + } + }, + }, + } + output = tmp_path + options = { + "filename": "out.tar.gz", + } + options.update(test_options) + + stage_module.main(inp, output, options) + assert len(mocked_run.call_args_list) == 1 + args, kwargs = mocked_run.call_args_list[0] + assert args == (["gzip", "--no-name", "--stdout", expected_level, "/input/file/path/hash:value"],) + assert kwargs["check"] + assert kwargs["stdout"].name.endswith("out.tar.gz")