Skip to content

Commit

Permalink
tests: Add tests for custom_script builder
Browse files Browse the repository at this point in the history
Add tests for custom_script builder

Signed-off-by: Dmytro Semenets <[email protected]>
  • Loading branch information
dsemenets committed Mar 4, 2024
1 parent 4a0ee2d commit 2d840d3
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/integration_tests/custom_script_builder/script.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"

Original file line number Diff line number Diff line change
@@ -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__])
Original file line number Diff line number Diff line change
@@ -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"

Original file line number Diff line number Diff line change
@@ -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__])
Original file line number Diff line number Diff line change
@@ -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"

Original file line number Diff line number Diff line change
@@ -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__])

0 comments on commit 2d840d3

Please sign in to comment.