-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add tests for custom_script builder
Add tests for custom_script builder Signed-off-by: Dmytro Semenets <[email protected]>
- Loading branch information
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
...ntegration_tests/custom_script_builder/test_args_is_list/resources/test_args_is_list.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
32 changes: 32 additions & 0 deletions
32
tests/integration_tests/custom_script_builder/test_args_is_list/test_args_is_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__]) |
12 changes: 12 additions & 0 deletions
12
...ration_tests/custom_script_builder/test_args_is_string/resources/test_args_is_string.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
32 changes: 32 additions & 0 deletions
32
tests/integration_tests/custom_script_builder/test_args_is_string/test_args_is_string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__]) |
11 changes: 11 additions & 0 deletions
11
...ntegration_tests/custom_script_builder/test_args_missing/resources/test_args_missing.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
32 changes: 32 additions & 0 deletions
32
tests/integration_tests/custom_script_builder/test_args_missing/test_args_missing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__]) |