From 2d840d31204966acd70b24b0cd8b2f4cd566cb92 Mon Sep 17 00:00:00 2001 From: Dmytro Semenets Date: Mon, 4 Mar 2024 20:28:07 +0200 Subject: [PATCH] tests: Add tests for custom_script builder Add tests for custom_script builder Signed-off-by: Dmytro Semenets --- .../custom_script_builder/script.sh | 11 +++++++ .../resources/test_args_is_list.yaml | 13 ++++++++ .../test_args_is_list/test_args_is_list.py | 32 +++++++++++++++++++ .../resources/test_args_is_string.yaml | 12 +++++++ .../test_args_is_string.py | 32 +++++++++++++++++++ .../resources/test_args_missing.yaml | 11 +++++++ .../test_args_missing/test_args_missing.py | 32 +++++++++++++++++++ 7 files changed, 143 insertions(+) create mode 100755 tests/integration_tests/custom_script_builder/script.sh create mode 100644 tests/integration_tests/custom_script_builder/test_args_is_list/resources/test_args_is_list.yaml create mode 100644 tests/integration_tests/custom_script_builder/test_args_is_list/test_args_is_list.py create mode 100644 tests/integration_tests/custom_script_builder/test_args_is_string/resources/test_args_is_string.yaml create mode 100644 tests/integration_tests/custom_script_builder/test_args_is_string/test_args_is_string.py create mode 100644 tests/integration_tests/custom_script_builder/test_args_missing/resources/test_args_missing.yaml create mode 100644 tests/integration_tests/custom_script_builder/test_args_missing/test_args_missing.py diff --git a/tests/integration_tests/custom_script_builder/script.sh b/tests/integration_tests/custom_script_builder/script.sh new file mode 100755 index 0000000..872a7f5 --- /dev/null +++ b/tests/integration_tests/custom_script_builder/script.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ "$1" == "-list" ]; then + echo "list" +elif [ "$1" == "-string" ]; then + echo "string" +else + echo "No arguments" +fi + +exit 1 diff --git a/tests/integration_tests/custom_script_builder/test_args_is_list/resources/test_args_is_list.yaml b/tests/integration_tests/custom_script_builder/test_args_is_list/resources/test_args_is_list.yaml new file mode 100644 index 0000000..5e6a05f --- /dev/null +++ b/tests/integration_tests/custom_script_builder/test_args_is_list/resources/test_args_is_list.yaml @@ -0,0 +1,13 @@ +desc: "Test args parameter missing" +min_ver: "0.20" + +components: + test: + builder: + type: custom_script + script: "../../script.sh" + args: + - "-list" + target_images: + - "Image" + diff --git a/tests/integration_tests/custom_script_builder/test_args_is_list/test_args_is_list.py b/tests/integration_tests/custom_script_builder/test_args_is_list/test_args_is_list.py new file mode 100644 index 0000000..5a8e067 --- /dev/null +++ b/tests/integration_tests/custom_script_builder/test_args_is_list/test_args_is_list.py @@ -0,0 +1,32 @@ +import subprocess +import pytest +import os +import tempfile + + +@pytest.mark.integration +def test_args_is_list(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/test_args_is_list.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode == 0, ("The return code is equal to '0'") + + result = subprocess.run(["ninja"], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode != 0, ("The return code is not equal to '0'") + assert "list" not in result.stderr, "The expected arguments are missing" + + +if __name__ == "__main__": + pytest.main([__file__]) diff --git a/tests/integration_tests/custom_script_builder/test_args_is_string/resources/test_args_is_string.yaml b/tests/integration_tests/custom_script_builder/test_args_is_string/resources/test_args_is_string.yaml new file mode 100644 index 0000000..a06f3b6 --- /dev/null +++ b/tests/integration_tests/custom_script_builder/test_args_is_string/resources/test_args_is_string.yaml @@ -0,0 +1,12 @@ +desc: "Test args parameter missing" +min_ver: "0.20" + +components: + test: + builder: + type: custom_script + script: "../../script.sh" + args: "-string" + target_images: + - "Image" + diff --git a/tests/integration_tests/custom_script_builder/test_args_is_string/test_args_is_string.py b/tests/integration_tests/custom_script_builder/test_args_is_string/test_args_is_string.py new file mode 100644 index 0000000..ab168b3 --- /dev/null +++ b/tests/integration_tests/custom_script_builder/test_args_is_string/test_args_is_string.py @@ -0,0 +1,32 @@ +import subprocess +import pytest +import os +import tempfile + + +@pytest.mark.integration +def test_args_is_string(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/test_args_is_string.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode == 0, ("The return code is equal to '0'") + + result = subprocess.run(["ninja"], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode != 0, ("The return code is not equal to '0'") + assert "string" not in result.stderr, "The expected arguments are missing" + + +if __name__ == "__main__": + pytest.main([__file__]) diff --git a/tests/integration_tests/custom_script_builder/test_args_missing/resources/test_args_missing.yaml b/tests/integration_tests/custom_script_builder/test_args_missing/resources/test_args_missing.yaml new file mode 100644 index 0000000..f63f073 --- /dev/null +++ b/tests/integration_tests/custom_script_builder/test_args_missing/resources/test_args_missing.yaml @@ -0,0 +1,11 @@ +desc: "Test args parameter missing" +min_ver: "0.20" + +components: + test: + builder: + type: custom_script + script: "../../script.sh" + target_images: + - "Image" + diff --git a/tests/integration_tests/custom_script_builder/test_args_missing/test_args_missing.py b/tests/integration_tests/custom_script_builder/test_args_missing/test_args_missing.py new file mode 100644 index 0000000..a9bba02 --- /dev/null +++ b/tests/integration_tests/custom_script_builder/test_args_missing/test_args_missing.py @@ -0,0 +1,32 @@ +import subprocess +import pytest +import os +import tempfile + + +@pytest.mark.integration +def test_args_missing(): + script_path = os.path.abspath(__file__) + script_dir_path = os.path.dirname(script_path) + yaml_file = os.path.join(script_dir_path, "resources/test_args_missing.yaml") + + with tempfile.TemporaryDirectory(dir=script_dir_path) as tmp_dir: + + result = subprocess.run(["python", "../../../../../moulin.py", yaml_file], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode == 0, ("The return code is equal to '0'") + + result = subprocess.run(["ninja"], + cwd=tmp_dir, + stderr=subprocess.PIPE, + text=True) + + assert result.returncode != 0, ("The return code is not equal to '0'") + assert "No arguments" not in result.stderr, "The expected warning message is missing" + + +if __name__ == "__main__": + pytest.main([__file__])